diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-05-31 19:15:08 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-05-31 19:15:08 -0500 |
| commit | cc5d80202e6f5973a0ce1bbdb30635392aa07ada (patch) | |
| tree | f80c0ffd2323cc58499b2bf563707691ad937ae4 /src/slskd/Common/FileSafety.cs | |
| parent | 046c60b817144b46d82c4311d166e6ba78062a90 (diff) | |
| download | slskd-cc5d80202e6f5973a0ce1bbdb30635392aa07ada.tar.gz | |
tweak root handling
Diffstat (limited to 'src/slskd/Common/FileSafety.cs')
| -rw-r--r-- | src/slskd/Common/FileSafety.cs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/slskd/Common/FileSafety.cs b/src/slskd/Common/FileSafety.cs index 1fff4b08..650c082b 100644 --- a/src/slskd/Common/FileSafety.cs +++ b/src/slskd/Common/FileSafety.cs @@ -247,7 +247,7 @@ public static class FileSafety /// <summary> /// Returns the full directory name from the specified <paramref name="path"/>, properly handling both - /// forward and backslashes, removing Windows drive, UNC and Soulseek QT root segments and sanitizing + /// forward and backslashes, removing Windows drive, UNC and Soulseek QT root segments, and sanitizing /// each of the remaining segments. /// </summary> /// <param name="path">The path from which to extract the directory name.</param> @@ -269,7 +269,7 @@ public static class FileSafety return null; } - var isUNC = path.StartsWith("//") || path.StartsWith("\\\\"); + var leadingSlashCount = path.TakeWhile(c => c == '/' || c == '\\').Count(); os ??= Compute.OSPlatform(); var sep = os.Value == OSPlatform.Windows ? '\\' : '/'; @@ -307,7 +307,12 @@ public static class FileSafety .SkipLast(1) .Select(s => sanitize ? SanitizePathSegment(s, os: os) : s)); - return (retainRoot && isUNC) ? $"{sep}{sep}{newPath}" : newPath; + if (retainRoot) + { + return new string(sep, leadingSlashCount) + newPath; + } + + return newPath; } /// <summary> |
