aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/CommonExtensions.cs4
-rw-r--r--src/slskd/Transfers/Downloads/DownloadService.cs7
2 files changed, 6 insertions, 5 deletions
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs
index 33e59382..5ff3e519 100644
--- a/src/slskd/Common/CommonExtensions.cs
+++ b/src/slskd/Common/CommonExtensions.cs
@@ -393,7 +393,7 @@ namespace slskd
[Obsolete("Find something more intelligent to do instead of this")]
public static string ToLocalFilename(this string remoteFilename, string baseDirectory)
{
- return Path.Combine(baseDirectory, remoteFilename.ToLocalRelativeFilename());
+ return FileSafety.CombineSafely(baseDirectory, remoteFilename.ToLocalRelativeFilename());
}
/// <summary>
@@ -467,7 +467,7 @@ namespace slskd
var file = parts.Last().ReplaceInvalidFileNameCharacters();
var directory = parts.Reverse().Skip(1).Take(1).Single().ReplaceInvalidFileNameCharacters();
- return Path.Combine(directory, file);
+ return FileSafety.CombineSafely(directory, file);
}
/// <summary>
diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs
index 184acb5d..7d9d9521 100644
--- a/src/slskd/Transfers/Downloads/DownloadService.cs
+++ b/src/slskd/Transfers/Downloads/DownloadService.cs
@@ -1046,10 +1046,11 @@ namespace slskd.Transfers.Downloads
// if the transfer has an associated batch id, store the incomplete file in a directory of the same name
// this is to ensure maximal safety when resuming failed downloads (otherwise we risk resuming an unrelated file)
+ // if there is no batch id, sanitize the username and use that
var incompleteFilename = transfer.Filename.ToLocalFilename(
- baseDirectory: System.IO.Path.Combine(
+ baseDirectory: FileSafety.CombineSafely(
OptionsMonitor.CurrentValue.Directories.Incomplete,
- transfer.BatchId.HasValue ? transfer.BatchId.ToString() : string.Empty));
+ transfer.BatchId.HasValue ? transfer.BatchId.ToString() : transfer.Username.ReplaceInvalidFileNameCharacters()));
Log.Debug("Invoking Soulseek DownloadAsync() for {Filename} from {Username}", transfer.Filename, transfer.Username);
transfer.Attempts = 1;
@@ -1144,7 +1145,7 @@ namespace slskd.Transfers.Downloads
{
// if the transfer has an associated batch id, then:
// some/long/remote/path/folder/file.ext -> download_directory/batch_id/file.ext
- destinationDirectory = System.IO.Path.Combine(OptionsMonitor.CurrentValue.Directories.Downloads, transfer.BatchId.Value.ToString());
+ destinationDirectory = FileSafety.CombineSafely(OptionsMonitor.CurrentValue.Directories.Downloads, transfer.BatchId.Value.ToString());
}
else
{