diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-08-13 17:22:34 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-08-13 17:22:34 -0500 |
| commit | 123a1ecbc0bb950fb90e210d6cb24777dc3d97ce (patch) | |
| tree | 2eb167442a3fa2ed125d39bc9f28dfe945a14314 /src | |
| parent | 188dc599015bef3ca85d6dd4f5eebdf4356b92bb (diff) | |
| download | slskd-123a1ecbc0bb950fb90e210d6cb24777dc3d97ce.tar.gz | |
fix existing transfer detection
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Transfers/Uploads/UploadService.cs | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs index 4dc6e30d..c4726333 100644 --- a/src/slskd/Transfers/Uploads/UploadService.cs +++ b/src/slskd/Transfers/Uploads/UploadService.cs @@ -106,17 +106,10 @@ namespace slskd.Transfers.Uploads /// <returns>The operation context.</returns> public async Task EnqueueAsync(string username, string filename) { - // remote clients might sometimes re-request downloads to check the status. don't try to add the download again if it - // is already tracked. - if (await ExistsAsync(t => t.Username == username && t.Filename == filename)) - { - return; - } - string localFilename; FileInfo fileInfo = default; - Log.Information("[{Context}] {Username} requested {Filename}]", "UPLOAD REQUESTED", username, filename); + Log.Information("[{Context}] {Username} requested {Filename}", "UPLOAD REQUESTED", username, filename); try { @@ -135,6 +128,16 @@ namespace slskd.Transfers.Uploads throw new DownloadEnqueueException($"File not shared."); } + // find existing records for this username and file that haven't been removed from the UI + var existingRecords = await ListAsync(t => t.Username == username && t.Filename == localFilename && !t.Removed); + + // check whether any of these records is in a non-complete state and bail out if so + if (existingRecords.Any(t => !t.State.HasFlag(TransferStates.Completed))) + { + Log.Information("Upload {Filename} to {Username} is already queued or in progress", localFilename, username); + return; + } + var id = Guid.NewGuid(); var transfer = new Transfer() @@ -222,16 +225,6 @@ namespace slskd.Transfers.Uploads } /// <summary> - /// Returns a value indicating whether an upload matching the specified <paramref name="expression"/> exists. - /// </summary> - /// <param name="expression">The expression used to match uploads.</param> - /// <returns>A value indicating whether an upload matching the specified expression exists.</returns> - public async Task<bool> ExistsAsync(Expression<Func<Transfer, bool>> expression) - { - return (await FindAsync(expression)) != default; - } - - /// <summary> /// Finds a single upload matching the specified <paramref name="expression"/>. /// </summary> /// <param name="expression">The expression to use to match uploads.</param> |
