From 123a1ecbc0bb950fb90e210d6cb24777dc3d97ce Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 13 Aug 2022 17:22:34 -0500 Subject: fix existing transfer detection --- src/slskd/Transfers/Uploads/UploadService.cs | 29 +++++++++++----------------- 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'src') 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 /// The operation context. 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() @@ -221,16 +224,6 @@ namespace slskd.Transfers.Uploads }); } - /// - /// Returns a value indicating whether an upload matching the specified exists. - /// - /// The expression used to match uploads. - /// A value indicating whether an upload matching the specified expression exists. - public async Task ExistsAsync(Expression> expression) - { - return (await FindAsync(expression)) != default; - } - /// /// Finds a single upload matching the specified . /// -- cgit v1.2.3