From 2e8e4ae3ae5ccf9956f39d3b3979a90243dd28be Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Sun, 21 Jun 2026 23:00:56 -0500 Subject: [PATCH] Allow selected local files for archive upload to be moved instead of copied Fixes #413 --- .../ArchiveService.cs | 20 +++++++++++++++++-- .../UI/Components/ArchiveUploader.razor | 11 +++++++++- .../UI/Components/ImportUploadDialog.razor | 4 ++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/LANCommander.Server.Services/ArchiveService.cs b/LANCommander.Server.Services/ArchiveService.cs index 24f798bc..56036922 100644 --- a/LANCommander.Server.Services/ArchiveService.cs +++ b/LANCommander.Server.Services/ArchiveService.cs @@ -189,7 +189,7 @@ namespace LANCommander.Server.Services return File.Exists(path); } - public async Task CopyFromLocalFileAsync(string path, Guid storageLocationId) + public async Task CopyFromLocalFileAsync(string path, Guid storageLocationId, bool move = false) { var storageLocation = await storageLocationService.GetAsync(storageLocationId); @@ -212,7 +212,23 @@ namespace LANCommander.Server.Services if (!string.IsNullOrEmpty(archiveDirectory) && !Directory.Exists(archiveDirectory)) Directory.CreateDirectory(archiveDirectory); - File.Copy(path, archivePath, true); + if (move) + { + try + { + File.Move(path, archivePath, true); + } + catch (IOException ex) + { + _logger.LogInformation(ex, "Could not move local file from {SourcePath} to {DestinationPath}, falling back to copy", path, archivePath); + + File.Copy(path, archivePath, true); + } + } + else + { + File.Copy(path, archivePath, true); + } return Guid.Parse(archive.ObjectKey); } diff --git a/LANCommander.Server/UI/Components/ArchiveUploader.razor b/LANCommander.Server/UI/Components/ArchiveUploader.razor index 3d4eec26..c187247d 100644 --- a/LANCommander.Server/UI/Components/ArchiveUploader.razor +++ b/LANCommander.Server/UI/Components/ArchiveUploader.razor @@ -4,6 +4,7 @@ @using LANCommander.UI.Services @using Microsoft.Extensions.Options @inject ArchiveService ArchiveService +@inject StorageLocationService StorageLocationService @inject IOptions Settings @inject IMessageService MessageService @inject ConfirmService ConfirmService @@ -13,6 +14,9 @@ @{ RenderFragment Footer = @