aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-05-30 15:40:29 -0500
committerJP Dillingham <jp@dillingham.me>2026-05-30 15:40:29 -0500
commit062d282403cc03c3fdd4101742647be6a83d0329 (patch)
tree2eb8b45436b467e97fc62c7901535060e697a898 /src
parentebf7c753f385c558cc1442609eaa17d2eb32e6da (diff)
downloadslskd-062d282403cc03c3fdd4101742647be6a83d0329.tar.gz
extract StripPathRoot
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/FileSafety.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/slskd/Common/FileSafety.cs b/src/slskd/Common/FileSafety.cs
index 93a91faa..a175ebbd 100644
--- a/src/slskd/Common/FileSafety.cs
+++ b/src/slskd/Common/FileSafety.cs
@@ -365,4 +365,27 @@ public static class FileSafety
return string.Join(sep, segments);
}
+
+ /// <summary>
+ /// Removes the root of the specified <paramref name="path"/>, including Window's drive prefix (e.g. C:\),
+ /// UNC paths on any OS (e.g. \\server on Windows, //server on Linux), and drops the hashed prefix added by
+ /// Soulseek Qt to hide the path on disk (e.g. @@abcde).
+ /// </summary>
+ /// <param name="path">The path to strip.</param>
+ /// <param name="os">An optional operating system override, for testing.</param>
+ /// <returns>The path with the root stripped, if one was present.</returns>
+ public static string StripPathRoot(string path, OSPlatform? os = null)
+ {
+ // flip slashes the correct way
+ path = LocalizePath(path, os);
+
+ // strip C:\ or //server, if present (regardless of slash variant)
+ path = DriveRootRegex.Replace(path, string.Empty);
+ path = UncRootRegex.Replace(path, string.Empty);
+
+ // strip @@abcde prefixes used by SoulseekQt to obscure paths
+ path = SoulseekQtRootRegex.Replace(path, string.Empty);
+
+ return path;
+ }
} \ No newline at end of file