aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-03-10 21:31:28 -0500
committerJP Dillingham <jp@dillingham.me>2026-03-10 21:31:28 -0500
commit76781b730a392f11af0548664c2928c89d013f5c (patch)
treeaa9b2a3e772735412ccc3dc89d339c89e162d18a /src
parentc4040a707823999d4612922a77ca6485dc1ca06f (diff)
downloadslskd-76781b730a392f11af0548664c2928c89d013f5c.tar.gz
derive incomplete file stats inside of retry loop to enable resume
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Transfers/Downloads/DownloadService.cs63
1 files changed, 41 insertions, 22 deletions
diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs
index 53730980..8f55a0c5 100644
--- a/src/slskd/Transfers/Downloads/DownloadService.cs
+++ b/src/slskd/Transfers/Downloads/DownloadService.cs
@@ -1014,33 +1014,52 @@ namespace slskd.Transfers.Downloads
: null;
var incompleteFilename = transfer.Filename.ToLocalFilename(baseDirectory: OptionsMonitor.CurrentValue.Directories.Incomplete);
- var incompleteFileInfo = Files.ResolveFileInfo(incompleteFilename);
- var incompleteStrategy = retryOptions.Incomplete.ToEnum<RetryIncompleteStrategy>();
-
- bool shouldResume = incompleteFileInfo.Exists && incompleteFileInfo.Length > 0 && incompleteStrategy == RetryIncompleteStrategy.Resume;
Log.Debug("Invoking Soulseek DownloadAsync() for {Filename} from {Username}", transfer.Filename, transfer.Username);
transfer.Attempts = 1;
SynchronizedUpdate(transfer, semaphore: updateSyncRoot, cancellationToken: CancellationToken.None);
- var completedTransfer = await Retry.Do(() => Client.DownloadAsync(
- username: transfer.Username,
- remoteFilename: transfer.Filename,
- outputStreamFactory: () => Task.FromResult(
- Files.CreateFile(
- filename: incompleteFilename,
- options: new CreateFileOptions
- {
- Access = System.IO.FileAccess.Write,
- Mode = shouldResume ? System.IO.FileMode.Append : System.IO.FileMode.Create,
- Share = System.IO.FileShare.None, // exclusive access for the duration of the download
- UnixCreateMode = unixFileMode,
- })),
- size: transfer.Size,
- startOffset: shouldResume ? incompleteFileInfo.Length : 0,
- token: null,
- cancellationToken: cancellationToken,
- options: topts),
+ var completedTransfer = await Retry.Do(() =>
+ {
+ var incompleteFileInfo = Files.ResolveFileInfo(incompleteFilename);
+ var incompleteStrategy = retryOptions.Incomplete.ToEnum<RetryIncompleteStrategy>();
+
+ var shouldResume = false;
+ var startOffset = 0L;
+
+ if (incompleteFileInfo.Exists && incompleteFileInfo.Length > 0)
+ {
+ if (incompleteStrategy == RetryIncompleteStrategy.Resume)
+ {
+ shouldResume = true;
+ startOffset = incompleteFileInfo.Length;
+ Log.Information("Resuming download of {Filename} from user {Username} at offset {Offet}", transfer.Filename, transfer.Username, incompleteFileInfo.Length);
+ }
+ else
+ {
+ Log.Information("Overwriting partial download of {Length} bytes for download of {Filename} from user {Username} at offset {Offet}", incompleteFileInfo.Length, transfer.Filename, transfer.Username);
+ }
+ }
+
+ return Client.DownloadAsync(
+ username: transfer.Username,
+ remoteFilename: transfer.Filename,
+ outputStreamFactory: () => Task.FromResult(
+ Files.CreateFile(
+ filename: incompleteFilename,
+ options: new CreateFileOptions
+ {
+ Access = System.IO.FileAccess.Write,
+ Mode = shouldResume ? System.IO.FileMode.Append : System.IO.FileMode.Create,
+ Share = System.IO.FileShare.None, // exclusive access for the duration of the download
+ UnixCreateMode = unixFileMode,
+ })),
+ size: transfer.Size,
+ startOffset: startOffset,
+ token: null,
+ cancellationToken: cancellationToken,
+ options: topts);
+ },
isRetryable: (attempts, ex) =>
ex is not OperationCanceledException
&& ex is not TransferRejectedException