aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-05-31 19:15:08 -0500
committerJP Dillingham <jp@dillingham.me>2026-05-31 19:15:08 -0500
commitcc5d80202e6f5973a0ce1bbdb30635392aa07ada (patch)
treef80c0ffd2323cc58499b2bf563707691ad937ae4 /src/slskd
parent046c60b817144b46d82c4311d166e6ba78062a90 (diff)
downloadslskd-cc5d80202e6f5973a0ce1bbdb30635392aa07ada.tar.gz
tweak root handling
Diffstat (limited to 'src/slskd')
-rw-r--r--src/slskd/Common/FileSafety.cs11
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>