[PATCH 0/2] MR3259: Add environment variable to isolate WINEPREFIX at creation
I'm aware that winecfg allows unlinking of symlinked folders, but this is very annoying when regularly recreating WINEPREFIXES. This change makes it easy to isolate those folders from the start. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/3259
From: Fabian Maurer <dark.shadow4(a)web.de> --- dlls/shell32/shellpath.c | 44 +++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/dlls/shell32/shellpath.c b/dlls/shell32/shellpath.c index 5dd9f4b6310..06358de203f 100644 --- a/dlls/shell32/shellpath.c +++ b/dlls/shell32/shellpath.c @@ -2778,6 +2778,26 @@ done: CloseHandle( mgr ); } +static BOOL isolate_folder(const char *folder) +{ + char buffer[200]; + char *current, *next; + const char *isolate = getenv("WINEISOLATE"); + + if (!isolate || strlen(isolate) > ARRAY_SIZE(buffer)) + return FALSE; + + strcpy(buffer, isolate); + current = strtok_s(buffer, ",", &next); + while (current) + { + if (!strcmp(current, folder)) + return TRUE; + current = strtok(NULL, ","); + } + return FALSE; +} + /****************************************************************************** * _SHCreateSymbolicLink [Internal] * @@ -2789,29 +2809,39 @@ done: */ static void _SHCreateSymbolicLink(int nFolder, const WCHAR *path) { + BOOL isolate_all = isolate_folder("home"); DWORD folder = nFolder & CSIDL_FOLDER_MASK; + if (isolate_all) return; + switch (folder) { case CSIDL_PERSONAL: - create_link( path, "XDG_DOCUMENTS_DIR", "$HOME/Documents" ); + if (!isolate_folder("documents")) + create_link( path, "XDG_DOCUMENTS_DIR", "$HOME/Documents" ); break; case CSIDL_DESKTOPDIRECTORY: - create_link( path, "XDG_DESKTOP_DIR", "$HOME/Desktop" ); + if (!isolate_folder("desktop")) + create_link( path, "XDG_DESKTOP_DIR", "$HOME/Desktop" ); break; case CSIDL_MYPICTURES: - create_link( path, "XDG_PICTURES_DIR", "$HOME/Pictures" ); + if (!isolate_folder("pictures")) + create_link( path, "XDG_PICTURES_DIR", "$HOME/Pictures" ); break; case CSIDL_MYVIDEO: - create_link( path, "XDG_VIDEOS_DIR", "$HOME/Movies" ); + if (!isolate_folder("movies")) + create_link( path, "XDG_VIDEOS_DIR", "$HOME/Movies" ); break; case CSIDL_MYMUSIC: - create_link( path, "XDG_MUSIC_DIR", "$HOME/Music" ); + if (!isolate_folder("music")) + create_link( path, "XDG_MUSIC_DIR", "$HOME/Music" ); break; case CSIDL_DOWNLOADS: - create_link( path, "XDG_DOWNLOAD_DIR", "$HOME/Downloads" ); + if (!isolate_folder("downloads")) + create_link( path, "XDG_DOWNLOAD_DIR", "$HOME/Downloads" ); break; case CSIDL_TEMPLATES: - create_link( path, "XDG_TEMPLATES_DIR", "$HOME/Templates" ); + if (!isolate_folder("templates")) + create_link( path, "XDG_TEMPLATES_DIR", "$HOME/Templates" ); break; } } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/3259
From: Fabian Maurer <dark.shadow4(a)web.de> --- dlls/ntdll/unix/server.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/dlls/ntdll/unix/server.c b/dlls/ntdll/unix/server.c index e5e234d05ae..b84f53806c3 100644 --- a/dlls/ntdll/unix/server.c +++ b/dlls/ntdll/unix/server.c @@ -1269,6 +1269,26 @@ static const char *init_server_dir( dev_t dev, ino_t ino ) return dir; } +/* Copied from shell32/shellpath, changed to use strtok */ +static BOOL isolate_folder(const char *folder) +{ + char buffer[200]; + char *current; + const char *isolate = getenv("WINEISOLATE"); + + if (!isolate || strlen(isolate) > ARRAY_SIZE(buffer)) + return FALSE; + + strcpy(buffer, isolate); + current = strtok(buffer, ","); + while (current) + { + if (!strcmp(current, folder)) + return TRUE; + current = strtok(NULL, ","); + } + return FALSE; +} /*********************************************************************** * setup_config_dir @@ -1307,7 +1327,8 @@ static int setup_config_dir(void) { mkdir( "drive_c", 0777 ); symlink( "../drive_c", "dosdevices/c:" ); - symlink( "/", "dosdevices/z:" ); + if (!isolate_folder("root")) + symlink( "/", "dosdevices/z:" ); } else if (errno != EEXIST) fatal_perror( "cannot create %s/dosdevices", config_dir ); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/3259
Note that the ntdll change uses strtok which is not threadsafe - I hope this is not an issue. I would have used strtok_s, but it's not available there. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/3259#note_38176
On Mon Jul 10 16:57:51 2023 +0000, Fabian Maurer wrote:
Note that the ntdll change uses strtok which is not threadsafe - I hope this is not an issue. I would have used strtok_s, but it's not available there. If thread safety matters here, could you use strtok_r?
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/3259#note_38549
participants (3)
-
Alex Henrie (@alexhenrie) -
Fabian Maurer -
Fabian Maurer (@DarkShadow44)