diff options
| -rw-r--r-- | src/slskd/Common/CommonExtensions.cs | 20 | ||||
| -rw-r--r-- | src/slskd/Shares/ShareService.cs | 9 | ||||
| -rw-r--r-- | src/slskd/Shares/SqliteShareRepository.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Transfers/Downloads/DownloadService.cs | 1 |
4 files changed, 26 insertions, 6 deletions
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs index 29383fcb..ed07f9ea 100644 --- a/src/slskd/Common/CommonExtensions.cs +++ b/src/slskd/Common/CommonExtensions.cs @@ -302,6 +302,26 @@ namespace slskd } /// <summary> + /// <see cref="Path.GetDirectoryName"/>, but for paths normalized to use backslashes. + /// </summary> + /// <param name="path"></param> + /// <returns></returns> + public static string GetNormalizedDirectoryName(this string path) + { + return string.Join('\\', path.Split('\\').SkipLast(1)); + } + + /// <summary> + /// <see cref="Path.GetFileName"/>, but for paths normalized to use backslashes. + /// </summary> + /// <param name="path"></param> + /// <returns></returns> + public static string GetNormalizedFileName(this string path) + { + return string.Join('\\', path.Split('\\').TakeLast(1)); + } + + /// <summary> /// Converts a fully qualified remote filename to a local filename, swapping directory characters for those specific /// to the local OS, removing any characters that are invalid for the local OS, and making the path relative to the /// remote store (including the filename and the parent folder). diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index 85cd2796..b36c7898 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -15,7 +15,6 @@ // along with this program. If not, see https://www.gnu.org/licenses/. // </copyright> -using System.IO; using Microsoft.Extensions.Options; namespace slskd.Shares @@ -145,7 +144,7 @@ namespace slskd.Shares if (share != null) { - prefix = share.RemotePath + Path.DirectorySeparatorChar; + prefix = share.RemotePath + (share.RemotePath.EndsWith('\\') ? string.Empty : '\\'); } // Soulseek requires that each directory in the tree have an entry in the list returned in a browse response. if @@ -161,12 +160,12 @@ namespace slskd.Shares var files = AllRepositories.SelectMany(r => r.ListFiles(prefix, includeFullPath: true)); var groups = files - .GroupBy(file => Path.GetDirectoryName(file.Filename)) + .GroupBy(file => file.Filename.GetNormalizedDirectoryName()) .Select(group => new Directory(group.Key, group.Select(f => { return new File( f.Code, - Path.GetFileName(f.Filename), // we can send the full path, or just the filename. save bandwidth and omit the path. + f.Filename.GetNormalizedFileName(), // we can send the full path, or just the filename. save bandwidth and omit the path. f.Size, f.Extension, f.Attributes); @@ -308,7 +307,7 @@ namespace slskd.Shares /// <returns>The summary information.</returns> public Task<(int Directories, int Files)> SummarizeShareAsync(Share share) { - var prefix = share.RemotePath + Path.DirectorySeparatorChar; + var prefix = share.RemotePath + (share.RemotePath.EndsWith('\\') ? string.Empty : '\\'); var dirs = AllRepositories.Select(r => r.CountDirectories(prefix)).Sum(); var files = AllRepositories.Select(r => r.CountFiles(prefix)).Sum(); diff --git a/src/slskd/Shares/SqliteShareRepository.cs b/src/slskd/Shares/SqliteShareRepository.cs index af402388..189cebb6 100644 --- a/src/slskd/Shares/SqliteShareRepository.cs +++ b/src/slskd/Shares/SqliteShareRepository.cs @@ -365,7 +365,7 @@ namespace slskd.Shares var attributeList = attributeJson.FromJson<List<FileAttribute>>(); - filename = includeFullPath ? filename : Path.GetFileName(filename); + filename = includeFullPath ? filename : filename.GetNormalizedFileName(); var file = new Soulseek.File(code, filename, size, extension, attributeList); diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index 2f06b665..1d1b6dfc 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -451,6 +451,7 @@ namespace slskd.Transfers.Downloads System.Diagnostics.Stopwatch sw = default; + // todo: remove this. or check that Path.GetFileName works as expected if it is to be kept if (experimental) { sw = new System.Diagnostics.Stopwatch(); |
