Matoking / protontricks

A wrapper that does winetricks things for Proton enabled games, requires Winetricks.
GNU General Public License v3.0
1.56k stars 35 forks source link

Protontricks crashes if the user does not have permission to access an invalid Steam Library Folder #277

Open robertkirkman opened 5 months ago

robertkirkman commented 5 months ago

Describe the bug PermissionError when the Steam installation has previously had a Steam Library Folder moved between a lot of different places and the user now has insufficient permissions for one of those places

To Reproduce

  1. Create a Steam Library Folder in an SD card at one mountpoint and add games to it
  2. Move the SD card mountpoint to a different path and change the permissions of the original mountpoint to deny the user
  3. Launch Protontricks

Expected behavior Protontricks should ignore any folder that the user does not have permission to access with the same behavior it currently exhibits for folders that do not exist

System (please complete the following information):

Additional context

Example command: protontricks 396280 --gui -vv Result:

protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_2026990.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_1493710.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_1222670.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_1887720.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_70.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_2348590.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_278360.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_391540.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_1628350.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_1070560.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_961940.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_216150.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_1391110.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_2225070.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_570.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_620.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_2144350.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_291550.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/.local/share/Steam/steamapps/appmanifest_228980.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Steam library folder /home/deck/sdcard not found. Protontricks might not have access to the directory.
protontricks (WARNING): Could not load manifest /home/myuser/sdcard/SteamLibrary/steamapps/appmanifest_70.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/sdcard/SteamLibrary/steamapps/appmanifest_544730.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/sdcard/SteamLibrary/steamapps/appmanifest_271590.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/sdcard/SteamLibrary/steamapps/appmanifest_1628350.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/sdcard/SteamLibrary/steamapps/appmanifest_2180100.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/sdcard/SteamLibrary/steamapps/appmanifest_730.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/sdcard/SteamLibrary/steamapps/appmanifest_396280.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/sdcard/SteamLibrary/steamapps/appmanifest_252950.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Skipping library folder /run/media/deck/sdcard due to insufficient permissions
protontricks (WARNING): Steam library folder /home/deck/sdcard/SteamLibrary not found. Protontricks might not have access to the directory.
protontricks (WARNING): Skipping library folder /run/media/deck/6a777f4f-8caa-4405-b6fb-221f42a301d7 due to insufficient permissions
protontricks (WARNING): Could not load manifest /home/myuser/sdcard/steamapps/appmanifest_220.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/sdcard/steamapps/appmanifest_70.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
protontricks (WARNING): Could not load manifest /home/myuser/sdcard/steamapps/appmanifest_544730.acf due to insufficient permissions. Error: [Errno 13] Permission denied: '/run/media/deck/sdcard'
Traceback (most recent call last):
  File "/usr/bin/protontricks", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/lib/python3.11/site-packages/protontricks/cli/main.py", line 32, in cli
    main(args)
  File "/usr/lib/python3.11/site-packages/protontricks/cli/util.py", line 159, in wrapper
    return cli_func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/protontricks/cli/main.py", line 244, in main
    steam_apps = get_steam_apps(
                 ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/protontricks/steam.py", line 1338, in get_steam_apps
    steam_apps += get_custom_windows_shortcuts(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/protontricks/steam.py", line 1205, in get_custom_windows_shortcuts
    prefix_path = find_appid_proton_prefix(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/protontricks/steam.py", line 799, in find_appid_proton_prefix
    steamapps_dirs = _get_steamapps_subdirs(path)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/protontricks/steam.py", line 308, in _get_steamapps_subdirs
    dirs = list(
           ^^^^^
  File "/usr/lib/python3.11/site-packages/protontricks/steam.py", line 308, in <genexpr>
    dirs = list(
               ^
  File "/usr/lib/python3.11/pathlib.py", line 931, in iterdir
    for name in os.listdir(self):
                ^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/run/media/deck/sdcard'
robertkirkman commented 5 months ago

Workaround that I created and used successfully to bypass this crash:

diff --git a/src/protontricks/steam.py b/src/protontricks/steam.py
index 403ef39..7b5378d 100644
--- a/src/protontricks/steam.py
+++ b/src/protontricks/steam.py
@@ -313,6 +313,9 @@ def _get_steamapps_subdirs(path):
     except FileNotFoundError:
         # Directory does not exist
         return []
+    except PermissionError:
+        # Permission denied to access directory
+        return []

     # Sort entries so that 'steamapps' is listed first, as it's the default
     # directory name that Steam uses and should thus be prioritized

I'm not sure whether the implementation and style of this workaround is sufficient for this repository. Maybe a more generalized, idiomatic implementation is possible.