From 188dc599015bef3ca85d6dd4f5eebdf4356b92bb Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 13 Aug 2022 17:22:18 -0500 Subject: remove ExistsAsync --- src/slskd/Transfers/Uploads/IUploadService.cs | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Uploads/IUploadService.cs b/src/slskd/Transfers/Uploads/IUploadService.cs index b902f20c..8e7e826f 100644 --- a/src/slskd/Transfers/Uploads/IUploadService.cs +++ b/src/slskd/Transfers/Uploads/IUploadService.cs @@ -53,13 +53,6 @@ namespace slskd.Transfers.Uploads /// The operation context. Task EnqueueAsync(string username, string filename); - /// - /// 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. - Task ExistsAsync(Expression> expression); - /// /// Finds a single upload matching the specified . /// -- cgit v1.2.3 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 From 7c2f9c6708fbb76a44f78fe7dd166c27d93a001c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 13 Aug 2022 17:34:36 -0500 Subject: remove unnecessary async --- src/slskd/Application.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index cf37d933..20f790fb 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -427,7 +427,7 @@ namespace slskd BrowseTracker.AddOrUpdate(args.Username, args); } - private async void Client_Connected(object sender, EventArgs e) + private void Client_Connected(object sender, EventArgs e) { ConnectionWatchdog.Stop(); Log.Information("Connected to the Soulseek server"); -- cgit v1.2.3 From b491037223b0772a533a29b55970e652bb04bfee Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 13 Aug 2022 18:25:47 -0500 Subject: handle FileNotFoundException when estimating place in queue --- src/slskd/Application.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index d0c9adc1..76934b43 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -667,6 +667,10 @@ namespace slskd var place = Transfers.Uploads.Queue.EstimatePosition(username, filename); return Task.FromResult((int?)place); } + catch (FileNotFoundException) + { + return Task.FromResult(null); + } catch (Exception ex) { Log.Warning(ex, "Failed to estimate place in queue for {Filename} requested by {Username}", filename, username); -- cgit v1.2.3