We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
wine sandboxing error in 0.5.3
Hello,
it seems you resolved issue #2114 but now, when I launch any of my wine games, I obtain this error message:
`[Errno 21] est un dossier: '/home/legluondunet/Games/test/drive_c/users/legluondunet/Downloads'`

* "est un dossier" = "is a folder"

then an other error message:
`en error prevented the game to launch`

I can reproduce this issue with all my installed wine game, **even with new installed game**.
Workaround: disable sandboxing...

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lutris/util/wine/prefix.py`
Content:
```
1 """Wine prefix management"""
2 import os
3 from lutris.util.wine.registry import WineRegistry
4 from lutris.util.log import logger
5 from lutris.util import joypad, system, i18n
6 from lutris.util.display import DISPLAY_MANAGER
7 
8 DESKTOP_KEYS = ["Desktop", "My Music", "My Pictures", "My Videos", "Personal"]
9 
10 
11 class WinePrefixManager:
12     """Class to allow modification of Wine prefixes without the use of Wine"""
13 
14     hkcu_prefix = "HKEY_CURRENT_USER"
15 
16     def __init__(self, path):
17         if not path:
18             logger.warning("No path specified for Wine prefix")
19         self.path = path
20 
21     def setup_defaults(self):
22         """Sets the defaults for newly created prefixes"""
23         self.override_dll("winemenubuilder.exe", "")
24         self.override_dll("steamwebhelper.exe", "")
25         try:
26             self.desktop_integration()
27         except OSError as ex:
28             logger.error("Failed to setup desktop integration, the prefix may not be valid.")
29             logger.exception(ex)
30 
31     def get_registry_path(self, key):
32         """Matches registry keys to a registry file
33 
34         Currently, only HKEY_CURRENT_USER keys are supported.
35         """
36         if key.startswith(self.hkcu_prefix):
37             return os.path.join(self.path, "user.reg")
38         raise ValueError("Unsupported key '{}'".format(key))
39 
40     def get_key_path(self, key):
41         if key.startswith(self.hkcu_prefix):
42             return key[len(self.hkcu_prefix) + 1:]
43         raise ValueError(
44             "The key {} is currently not supported by WinePrefixManager".format(key)
45         )
46 
47     def get_registry_key(self,key,subkey):
48         registry = WineRegistry(self.get_registry_path(key))
49         return registry.query(self.get_key_path(key),subkey)
50 
51     def set_registry_key(self, key, subkey, value):
52         registry = WineRegistry(self.get_registry_path(key))
53         registry.set_value(self.get_key_path(key), subkey, value)
54         registry.save()
55 
56     def clear_registry_key(self, key):
57         registry = WineRegistry(self.get_registry_path(key))
58         registry.clear_key(self.get_key_path(key))
59         registry.save()
60 
61     def clear_registry_subkeys(self, key, subkeys):
62         registry = WineRegistry(self.get_registry_path(key))
63         registry.clear_subkeys(self.get_key_path(key), subkeys)
64         registry.save()
65 
66     def override_dll(self, dll, mode):
67         key = self.hkcu_prefix + "/Software/Wine/DllOverrides"
68         if mode.startswith("dis"):
69             mode = ""
70         if mode not in ("builtin", "native", "builtin,native", "native,builtin", ""):
71             logger.error("DLL override '%s' mode is not valid", mode)
72             return
73         self.set_registry_key(key, dll, mode)
74 
75     def desktop_integration(self, desktop_dir=None):
76         """Overwrite desktop integration"""
77         DESKTOP_FOLDERS = []
78 
79         user = os.getenv("USER")
80         user_dir = os.path.join(self.path, "drive_c/users/", user)
81 
82         for key in DESKTOP_KEYS:
83             folder = self.get_registry_key(self.hkcu_prefix+"/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders",key)
84             DESKTOP_FOLDERS.append(folder[folder.rfind("\\")+1:]) 
85 
86         if not desktop_dir:
87             desktop_dir = user_dir
88         else:
89             desktop_dir = os.path.expanduser(desktop_dir)
90 
91         if system.path_exists(user_dir):
92             # Replace desktop integration symlinks
93             for item in DESKTOP_FOLDERS:
94                 path = os.path.join(user_dir, item)
95                 old_path = path + ".winecfg"
96 
97                 if os.path.islink(path):
98                     os.unlink(path)
99                 elif os.path.isdir(path):
100                     try:
101                         os.rmdir(path)
102                     # We can't delete nonempty dir, so we rename as wine do.
103                     except OSError:
104                         os.rename(path, old_path)
105 
106                 if desktop_dir != user_dir:
107                     src_path = os.path.join(desktop_dir, item)
108                     os.makedirs(src_path, exist_ok=True)
109                     os.symlink(src_path, path)
110                 else:
111                     # We use first the renamed dir, otherwise we make it.
112                     if os.path.isdir(old_path):
113                         os.rename(old_path, path)
114                     else:
115                         os.makedirs(path, exist_ok=True)
116 
117             # Security: Remove other symlinks.
118             for item in os.listdir(user_dir):
119                 if item not in DESKTOP_FOLDERS and os.path.islink(item):
120                     path = os.path.join(user_dir, item)
121                     os.unlink(path)
122                     os.makedirs(path)
123 
124     def set_crash_dialogs(self, enabled):
125         """Enable or diable Wine crash dialogs"""
126         self.set_registry_key(
127             self.hkcu_prefix + "/Software/Wine/WineDbg",
128             "ShowCrashDialog",
129             1 if enabled else 0,
130         )
131 
132     def set_virtual_desktop(self, enabled):
133         """Enable or disable wine virtual desktop.
134         The Lutris virtual desktop is refered to as 'WineDesktop', in Wine the
135         virtual desktop name is 'default'.
136         """
137         path = self.hkcu_prefix + "/Software/Wine/Explorer"
138         if enabled:
139             self.set_registry_key(path, "Desktop", "WineDesktop")
140             default_resolution = "x".join(DISPLAY_MANAGER.get_current_resolution())
141             logger.debug("Enabling wine virtual desktop with default resolution of %s",
142                          default_resolution)
143             self.set_registry_key(
144                 self.hkcu_prefix + "/Software/Wine/Explorer/Desktops",
145                 "WineDesktop",
146                 default_resolution
147             )
148         else:
149             self.clear_registry_key(path)
150 
151     def set_desktop_size(self, desktop_size):
152         """Sets the desktop size if one is given but do not reset the key if
153         one isn't.
154         """
155         path = self.hkcu_prefix + "/Software/Wine/Explorer/Desktops"
156         if desktop_size:
157             self.set_registry_key(path, "WineDesktop", desktop_size)
158 
159     def use_xvid_mode(self, enabled):
160         """Set this to "Y" to allow wine switch the resolution using XVidMode extension."""
161         self.set_registry_key(
162             self.hkcu_prefix + "/Software/Wine/X11 Driver",
163             "UseXVidMode",
164             "Y" if enabled else "N",
165         )
166 
167     def configure_joypads(self):
168         joypads = joypad.get_joypads()
169         key = self.hkcu_prefix + "/Software/Wine/DirectInput/Joysticks"
170         self.clear_registry_key(key)
171         for device, joypad_name in joypads:
172             if "event" in device:
173                 disabled_joypad = "{} (js)".format(joypad_name)
174             else:
175                 disabled_joypad = "{} (event)".format(joypad_name)
176             self.set_registry_key(key, disabled_joypad, "disabled")
177
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lutris/util/wine/prefix.py b/lutris/util/wine/prefix.py
--- a/lutris/util/wine/prefix.py
+++ b/lutris/util/wine/prefix.py
@@ -116,8 +116,8 @@
 
             # Security: Remove other symlinks.
             for item in os.listdir(user_dir):
-                if item not in DESKTOP_FOLDERS and os.path.islink(item):
-                    path = os.path.join(user_dir, item)
+                path = os.path.join(user_dir, item)
+                if item not in DESKTOP_FOLDERS and os.path.islink(path):
                     os.unlink(path)
                     os.makedirs(path)

{"golden_diff": "diff --git a/lutris/util/wine/prefix.py b/lutris/util/wine/prefix.py\n--- a/lutris/util/wine/prefix.py\n+++ b/lutris/util/wine/prefix.py\n@@ -116,8 +116,8 @@\n \n             # Security: Remove other symlinks.\n             for item in os.listdir(user_dir):\n-                if item not in DESKTOP_FOLDERS and os.path.islink(item):\n-                    path = os.path.join(user_dir, item)\n+                path = os.path.join(user_dir, item)\n+                if item not in DESKTOP_FOLDERS and os.path.islink(path):\n                     os.unlink(path)\n                     os.makedirs(path)\n", "issue": "wine sandboxing error in 0.5.3\nHello,\r\nit seems you resolved issue #2114 but now, when I launch any of my wine games, I obtain this error message:\r\n`[Errno 21] est un dossier: '/home/legluondunet/Games/test/drive_c/users/legluondunet/Downloads'`\r\n\r\n* \"est un dossier\" = \"is a folder\"\r\n\r\nthen an other error message:\r\n`en error prevented the game to launch`\r\n\r\nI can reproduce this issue with all my installed wine game, **even with new installed game**.\r\nWorkaround: disable sandboxing...\n", "before_files": [{"content": "\"\"\"Wine prefix management\"\"\"\nimport os\nfrom lutris.util.wine.registry import WineRegistry\nfrom lutris.util.log import logger\nfrom lutris.util import joypad, system, i18n\nfrom lutris.util.display import DISPLAY_MANAGER\n\nDESKTOP_KEYS = [\"Desktop\", \"My Music\", \"My Pictures\", \"My Videos\", \"Personal\"]\n\n\nclass WinePrefixManager:\n    \"\"\"Class to allow modification of Wine prefixes without the use of Wine\"\"\"\n\n    hkcu_prefix = \"HKEY_CURRENT_USER\"\n\n    def __init__(self, path):\n        if not path:\n            logger.warning(\"No path specified for Wine prefix\")\n        self.path = path\n\n    def setup_defaults(self):\n        \"\"\"Sets the defaults for newly created prefixes\"\"\"\n        self.override_dll(\"winemenubuilder.exe\", \"\")\n        self.override_dll(\"steamwebhelper.exe\", \"\")\n        try:\n            self.desktop_integration()\n        except OSError as ex:\n            logger.error(\"Failed to setup desktop integration, the prefix may not be valid.\")\n            logger.exception(ex)\n\n    def get_registry_path(self, key):\n        \"\"\"Matches registry keys to a registry file\n\n        Currently, only HKEY_CURRENT_USER keys are supported.\n        \"\"\"\n        if key.startswith(self.hkcu_prefix):\n            return os.path.join(self.path, \"user.reg\")\n        raise ValueError(\"Unsupported key '{}'\".format(key))\n\n    def get_key_path(self, key):\n        if key.startswith(self.hkcu_prefix):\n            return key[len(self.hkcu_prefix) + 1:]\n        raise ValueError(\n            \"The key {} is currently not supported by WinePrefixManager\".format(key)\n        )\n\n    def get_registry_key(self,key,subkey):\n        registry = WineRegistry(self.get_registry_path(key))\n        return registry.query(self.get_key_path(key),subkey)\n\n    def set_registry_key(self, key, subkey, value):\n        registry = WineRegistry(self.get_registry_path(key))\n        registry.set_value(self.get_key_path(key), subkey, value)\n        registry.save()\n\n    def clear_registry_key(self, key):\n        registry = WineRegistry(self.get_registry_path(key))\n        registry.clear_key(self.get_key_path(key))\n        registry.save()\n\n    def clear_registry_subkeys(self, key, subkeys):\n        registry = WineRegistry(self.get_registry_path(key))\n        registry.clear_subkeys(self.get_key_path(key), subkeys)\n        registry.save()\n\n    def override_dll(self, dll, mode):\n        key = self.hkcu_prefix + \"/Software/Wine/DllOverrides\"\n        if mode.startswith(\"dis\"):\n            mode = \"\"\n        if mode not in (\"builtin\", \"native\", \"builtin,native\", \"native,builtin\", \"\"):\n            logger.error(\"DLL override '%s' mode is not valid\", mode)\n            return\n        self.set_registry_key(key, dll, mode)\n\n    def desktop_integration(self, desktop_dir=None):\n        \"\"\"Overwrite desktop integration\"\"\"\n        DESKTOP_FOLDERS = []\n\n        user = os.getenv(\"USER\")\n        user_dir = os.path.join(self.path, \"drive_c/users/\", user)\n\n        for key in DESKTOP_KEYS:\n            folder = self.get_registry_key(self.hkcu_prefix+\"/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders\",key)\n            DESKTOP_FOLDERS.append(folder[folder.rfind(\"\\\\\")+1:]) \n\n        if not desktop_dir:\n            desktop_dir = user_dir\n        else:\n            desktop_dir = os.path.expanduser(desktop_dir)\n\n        if system.path_exists(user_dir):\n            # Replace desktop integration symlinks\n            for item in DESKTOP_FOLDERS:\n                path = os.path.join(user_dir, item)\n                old_path = path + \".winecfg\"\n\n                if os.path.islink(path):\n                    os.unlink(path)\n                elif os.path.isdir(path):\n                    try:\n                        os.rmdir(path)\n                    # We can't delete nonempty dir, so we rename as wine do.\n                    except OSError:\n                        os.rename(path, old_path)\n\n                if desktop_dir != user_dir:\n                    src_path = os.path.join(desktop_dir, item)\n                    os.makedirs(src_path, exist_ok=True)\n                    os.symlink(src_path, path)\n                else:\n                    # We use first the renamed dir, otherwise we make it.\n                    if os.path.isdir(old_path):\n                        os.rename(old_path, path)\n                    else:\n                        os.makedirs(path, exist_ok=True)\n\n            # Security: Remove other symlinks.\n            for item in os.listdir(user_dir):\n                if item not in DESKTOP_FOLDERS and os.path.islink(item):\n                    path = os.path.join(user_dir, item)\n                    os.unlink(path)\n                    os.makedirs(path)\n\n    def set_crash_dialogs(self, enabled):\n        \"\"\"Enable or diable Wine crash dialogs\"\"\"\n        self.set_registry_key(\n            self.hkcu_prefix + \"/Software/Wine/WineDbg\",\n            \"ShowCrashDialog\",\n            1 if enabled else 0,\n        )\n\n    def set_virtual_desktop(self, enabled):\n        \"\"\"Enable or disable wine virtual desktop.\n        The Lutris virtual desktop is refered to as 'WineDesktop', in Wine the\n        virtual desktop name is 'default'.\n        \"\"\"\n        path = self.hkcu_prefix + \"/Software/Wine/Explorer\"\n        if enabled:\n            self.set_registry_key(path, \"Desktop\", \"WineDesktop\")\n            default_resolution = \"x\".join(DISPLAY_MANAGER.get_current_resolution())\n            logger.debug(\"Enabling wine virtual desktop with default resolution of %s\",\n                         default_resolution)\n            self.set_registry_key(\n                self.hkcu_prefix + \"/Software/Wine/Explorer/Desktops\",\n                \"WineDesktop\",\n                default_resolution\n            )\n        else:\n            self.clear_registry_key(path)\n\n    def set_desktop_size(self, desktop_size):\n        \"\"\"Sets the desktop size if one is given but do not reset the key if\n        one isn't.\n        \"\"\"\n        path = self.hkcu_prefix + \"/Software/Wine/Explorer/Desktops\"\n        if desktop_size:\n            self.set_registry_key(path, \"WineDesktop\", desktop_size)\n\n    def use_xvid_mode(self, enabled):\n        \"\"\"Set this to \"Y\" to allow wine switch the resolution using XVidMode extension.\"\"\"\n        self.set_registry_key(\n            self.hkcu_prefix + \"/Software/Wine/X11 Driver\",\n            \"UseXVidMode\",\n            \"Y\" if enabled else \"N\",\n        )\n\n    def configure_joypads(self):\n        joypads = joypad.get_joypads()\n        key = self.hkcu_prefix + \"/Software/Wine/DirectInput/Joysticks\"\n        self.clear_registry_key(key)\n        for device, joypad_name in joypads:\n            if \"event\" in device:\n                disabled_joypad = \"{} (js)\".format(joypad_name)\n            else:\n                disabled_joypad = \"{} (event)\".format(joypad_name)\n            self.set_registry_key(key, disabled_joypad, \"disabled\")\n", "path": "lutris/util/wine/prefix.py"}], "after_files": [{"content": "\"\"\"Wine prefix management\"\"\"\nimport os\nfrom lutris.util.wine.registry import WineRegistry\nfrom lutris.util.log import logger\nfrom lutris.util import joypad, system, i18n\nfrom lutris.util.display import DISPLAY_MANAGER\n\nDESKTOP_KEYS = [\"Desktop\", \"My Music\", \"My Pictures\", \"My Videos\", \"Personal\"]\n\n\nclass WinePrefixManager:\n    \"\"\"Class to allow modification of Wine prefixes without the use of Wine\"\"\"\n\n    hkcu_prefix = \"HKEY_CURRENT_USER\"\n\n    def __init__(self, path):\n        if not path:\n            logger.warning(\"No path specified for Wine prefix\")\n        self.path = path\n\n    def setup_defaults(self):\n        \"\"\"Sets the defaults for newly created prefixes\"\"\"\n        self.override_dll(\"winemenubuilder.exe\", \"\")\n        self.override_dll(\"steamwebhelper.exe\", \"\")\n        try:\n            self.desktop_integration()\n        except OSError as ex:\n            logger.error(\"Failed to setup desktop integration, the prefix may not be valid.\")\n            logger.exception(ex)\n\n    def get_registry_path(self, key):\n        \"\"\"Matches registry keys to a registry file\n\n        Currently, only HKEY_CURRENT_USER keys are supported.\n        \"\"\"\n        if key.startswith(self.hkcu_prefix):\n            return os.path.join(self.path, \"user.reg\")\n        raise ValueError(\"Unsupported key '{}'\".format(key))\n\n    def get_key_path(self, key):\n        if key.startswith(self.hkcu_prefix):\n            return key[len(self.hkcu_prefix) + 1:]\n        raise ValueError(\n            \"The key {} is currently not supported by WinePrefixManager\".format(key)\n        )\n\n    def get_registry_key(self,key,subkey):\n        registry = WineRegistry(self.get_registry_path(key))\n        return registry.query(self.get_key_path(key),subkey)\n\n    def set_registry_key(self, key, subkey, value):\n        registry = WineRegistry(self.get_registry_path(key))\n        registry.set_value(self.get_key_path(key), subkey, value)\n        registry.save()\n\n    def clear_registry_key(self, key):\n        registry = WineRegistry(self.get_registry_path(key))\n        registry.clear_key(self.get_key_path(key))\n        registry.save()\n\n    def clear_registry_subkeys(self, key, subkeys):\n        registry = WineRegistry(self.get_registry_path(key))\n        registry.clear_subkeys(self.get_key_path(key), subkeys)\n        registry.save()\n\n    def override_dll(self, dll, mode):\n        key = self.hkcu_prefix + \"/Software/Wine/DllOverrides\"\n        if mode.startswith(\"dis\"):\n            mode = \"\"\n        if mode not in (\"builtin\", \"native\", \"builtin,native\", \"native,builtin\", \"\"):\n            logger.error(\"DLL override '%s' mode is not valid\", mode)\n            return\n        self.set_registry_key(key, dll, mode)\n\n    def desktop_integration(self, desktop_dir=None):\n        \"\"\"Overwrite desktop integration\"\"\"\n        DESKTOP_FOLDERS = []\n\n        user = os.getenv(\"USER\")\n        user_dir = os.path.join(self.path, \"drive_c/users/\", user)\n\n        for key in DESKTOP_KEYS:\n            folder = self.get_registry_key(self.hkcu_prefix+\"/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders\",key)\n            DESKTOP_FOLDERS.append(folder[folder.rfind(\"\\\\\")+1:]) \n\n        if not desktop_dir:\n            desktop_dir = user_dir\n        else:\n            desktop_dir = os.path.expanduser(desktop_dir)\n\n        if system.path_exists(user_dir):\n            # Replace desktop integration symlinks\n            for item in DESKTOP_FOLDERS:\n                path = os.path.join(user_dir, item)\n                old_path = path + \".winecfg\"\n\n                if os.path.islink(path):\n                    os.unlink(path)\n                elif os.path.isdir(path):\n                    try:\n                        os.rmdir(path)\n                    # We can't delete nonempty dir, so we rename as wine do.\n                    except OSError:\n                        os.rename(path, old_path)\n\n                if desktop_dir != user_dir:\n                    src_path = os.path.join(desktop_dir, item)\n                    os.makedirs(src_path, exist_ok=True)\n                    os.symlink(src_path, path)\n                else:\n                    # We use first the renamed dir, otherwise we make it.\n                    if os.path.isdir(old_path):\n                        os.rename(old_path, path)\n                    else:\n                        os.makedirs(path, exist_ok=True)\n\n            # Security: Remove other symlinks.\n            for item in os.listdir(user_dir):\n                path = os.path.join(user_dir, item)\n                if item not in DESKTOP_FOLDERS and os.path.islink(path):\n                    os.unlink(path)\n                    os.makedirs(path)\n\n    def set_crash_dialogs(self, enabled):\n        \"\"\"Enable or diable Wine crash dialogs\"\"\"\n        self.set_registry_key(\n            self.hkcu_prefix + \"/Software/Wine/WineDbg\",\n            \"ShowCrashDialog\",\n            1 if enabled else 0,\n        )\n\n    def set_virtual_desktop(self, enabled):\n        \"\"\"Enable or disable wine virtual desktop.\n        The Lutris virtual desktop is refered to as 'WineDesktop', in Wine the\n        virtual desktop name is 'default'.\n        \"\"\"\n        path = self.hkcu_prefix + \"/Software/Wine/Explorer\"\n        if enabled:\n            self.set_registry_key(path, \"Desktop\", \"WineDesktop\")\n            default_resolution = \"x\".join(DISPLAY_MANAGER.get_current_resolution())\n            logger.debug(\"Enabling wine virtual desktop with default resolution of %s\",\n                         default_resolution)\n            self.set_registry_key(\n                self.hkcu_prefix + \"/Software/Wine/Explorer/Desktops\",\n                \"WineDesktop\",\n                default_resolution\n            )\n        else:\n            self.clear_registry_key(path)\n\n    def set_desktop_size(self, desktop_size):\n        \"\"\"Sets the desktop size if one is given but do not reset the key if\n        one isn't.\n        \"\"\"\n        path = self.hkcu_prefix + \"/Software/Wine/Explorer/Desktops\"\n        if desktop_size:\n            self.set_registry_key(path, \"WineDesktop\", desktop_size)\n\n    def use_xvid_mode(self, enabled):\n        \"\"\"Set this to \"Y\" to allow wine switch the resolution using XVidMode extension.\"\"\"\n        self.set_registry_key(\n            self.hkcu_prefix + \"/Software/Wine/X11 Driver\",\n            \"UseXVidMode\",\n            \"Y\" if enabled else \"N\",\n        )\n\n    def configure_joypads(self):\n        joypads = joypad.get_joypads()\n        key = self.hkcu_prefix + \"/Software/Wine/DirectInput/Joysticks\"\n        self.clear_registry_key(key)\n        for device, joypad_name in joypads:\n            if \"event\" in device:\n                disabled_joypad = \"{} (js)\".format(joypad_name)\n            else:\n                disabled_joypad = \"{} (event)\".format(joypad_name)\n            self.set_registry_key(key, disabled_joypad, \"disabled\")\n", "path": "lutris/util/wine/prefix.py"}]}