From dcb1a3001bce0f7c08a852f1d5e7bb6ccaf6d47b Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Thu, 26 Nov 2026 10:30:28 -0500 Subject: [PATCH] fix(desktop): Downloads, Documents and game folder links work again without proot (#3273) Links made in a proot session store the guest path as their target, which the kernel cannot follow in the middle of a path once the session runs without proot: the folders listed, but nothing inside them could be opened or created. The desktop setup now makes a link again when it cannot be walked into, so it is stored in the form the current mode follows. --- .../usr/local/bin/droiddeck-desktop-games | 2 +- .../overlay/usr/local/bin/droiddeck-downloads | 2 +- tools/tests/test_desktop_downloads.py | 59 +++++++++++++++++++ tools/tests/test_steam_libraries.py | 22 +++++++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 tools/tests/test_desktop_downloads.py diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-desktop-games b/tools/linuxfs/overlay/usr/local/bin/droiddeck-desktop-games index 15fbee0d39..11853257d1 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-desktop-games +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-desktop-games @@ -115,7 +115,7 @@ def link_libraries(): common = os.path.join(library, "steamapps", "common") link = os.path.join(HOME, label) if os.path.isdir(common): - if os.path.islink(link) and os.readlink(link) == common: + if os.path.islink(link) and os.readlink(link) == common and os.path.isdir(os.path.join(link, ".")): continue if os.path.islink(link) or os.path.isfile(link): os.unlink(link) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-downloads b/tools/linuxfs/overlay/usr/local/bin/droiddeck-downloads index ce34e85919..fe84b79c7e 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-downloads +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-downloads @@ -10,7 +10,7 @@ free_name() { share() { local android=$HOME/Storage/$1 link=$HOME/$2 f [ -d "$android" ] && [ -w "$android" ] || return 0 - [ "$(readlink "$link" 2>/dev/null)" = "$android" ] && return 0 + [ "$(readlink "$link" 2>/dev/null)" = "$android" ] && [ -d "$link/." ] && return 0 if [ -L "$link" ]; then rm -f "$link" elif [ -d "$link" ]; then diff --git a/tools/tests/test_desktop_downloads.py b/tools/tests/test_desktop_downloads.py new file mode 100644 index 0000000000..4ef7373f6e --- /dev/null +++ b/tools/tests/test_desktop_downloads.py @@ -0,0 +1,59 @@ +import os +import subprocess +import tempfile +import unittest +from pathlib import Path + +SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-downloads" + + +class DesktopDownloadsTest(unittest.TestCase): + def run_script(self, home, shim=None): + env = dict(os.environ, HOME=str(home)) + if shim: + env["PATH"] = f"{shim}:{env['PATH']}" + subprocess.run(["bash", str(SCRIPT)], env=env, check=True) + + def make_home(self, temp): + home = Path(temp) / "home" + for name in ("Download", "Documents"): + (home / "Storage" / name).mkdir(parents=True) + return home + + def test_links_to_the_android_folders_are_made(self): + with tempfile.TemporaryDirectory() as temp: + home = self.make_home(temp) + self.run_script(home) + self.assertEqual(str(home / "Storage/Download"), os.readlink(home / "Downloads")) + self.assertEqual(str(home / "Storage/Documents"), os.readlink(home / "Documents")) + + def test_working_links_are_kept(self): + with tempfile.TemporaryDirectory() as temp: + home = self.make_home(temp) + self.run_script(home) + before = os.lstat(home / "Downloads").st_ino + self.run_script(home) + self.assertEqual(before, os.lstat(home / "Downloads").st_ino) + + def test_links_that_name_the_folder_but_cannot_be_walked_are_made_again(self): + with tempfile.TemporaryDirectory() as temp: + home = self.make_home(temp) + for link in ("Downloads", "Documents"): + os.symlink(str(Path(temp) / "gone"), home / link) + shim = Path(temp) / "bin" + shim.mkdir() + (shim / "readlink").write_text( + '#!/bin/bash\ncase "${@: -1}" in\n' + f' "{home}/Downloads") echo "{home}/Storage/Download" ;;\n' + f' "{home}/Documents") echo "{home}/Storage/Documents" ;;\n' + ' *) exec /usr/bin/readlink "$@" ;;\nesac\n') + (shim / "readlink").chmod(0o755) + self.run_script(home, shim) + for link, folder in (("Downloads", "Download"), ("Documents", "Documents")): + self.assertEqual(str(home / "Storage" / folder), os.readlink(home / link)) + self.assertTrue((home / link / ".").is_dir()) + self.assertEqual([], sorted(p.name for p in home.iterdir() if ".old." in p.name)) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_steam_libraries.py b/tools/tests/test_steam_libraries.py index 22955661d2..b32ac7d761 100644 --- a/tools/tests/test_steam_libraries.py +++ b/tools/tests/test_steam_libraries.py @@ -150,6 +150,28 @@ class CompatLibrariesTest(unittest.TestCase): class DesktopGamesTest(unittest.TestCase): + def test_library_links_that_cannot_be_walked_are_made_again(self): + with tempfile.TemporaryDirectory() as temp: + root = Path(temp) + steam, home = root / "Steam", root / "home" + (steam / "steamapps/common/Game").mkdir(parents=True) + home.mkdir() + common = str(steam / "steamapps/common") + stale, kept = home / "Steam Games", home / "SD Games" + os.symlink(str(root / "elsewhere"), stale) + card = root / "card/steamapps/common" + card.mkdir(parents=True) + os.symlink(str(card), kept) + before = os.lstat(kept).st_ino + real = os.readlink + with patch.object(desktop, "HOME", str(home)), \ + patch.object(desktop, "LIBRARIES", ((str(steam), "Steam Games"), (str(root / "card"), "SD Games"))), \ + patch.object(desktop.os, "readlink", lambda p: common if p == str(stale) else real(p)): + desktop.link_libraries() + self.assertEqual(common, os.readlink(stale)) + self.assertTrue((stale / "Game").is_dir()) + self.assertEqual(before, os.lstat(kept).st_ino) + def test_games_in_registered_libraries_get_entries(self): with tempfile.TemporaryDirectory() as temp: root = Path(temp)