diff --git a/server/RdtClient.Service/BackgroundServices/WatchFolderChecker.cs b/server/RdtClient.Service/BackgroundServices/WatchFolderChecker.cs index 21a6684..417dee5 100644 --- a/server/RdtClient.Service/BackgroundServices/WatchFolderChecker.cs +++ b/server/RdtClient.Service/BackgroundServices/WatchFolderChecker.cs @@ -107,12 +107,22 @@ public class WatchFolderChecker(ILogger logger, IServiceProv await torrentService.UploadMagnet(magnetLink, torrent); } - var processedPath = Path.Combine(processedStorePath, fileInfo.Name); - if (!Directory.Exists(processedStorePath)) { Directory.CreateDirectory(processedStorePath); } + + var processedPath = Path.Combine(processedStorePath, fileInfo.Name); + + if (File.Exists(processedPath)) + { + File.Delete(processedPath); + + logger.Log(LogLevel.Warning, + "File {torrentFileName} replaced in {processedStorePath} - it already existed and new torrent with same filename was added", + fileInfo.Name, + processedStorePath); + } File.Move(torrentFile, processedPath); @@ -126,6 +136,16 @@ public class WatchFolderChecker(ILogger logger, IServiceProv } var processedPath = Path.Combine(errorStorePath, fileInfo.Name); + + if (File.Exists(processedPath)) + { + File.Delete(processedPath); + + logger.Log(LogLevel.Warning, + "File {torrentFileName} replaced in {errorStorePath} - it already existed and new torrent with same filename was added", + fileInfo.Name, + errorStorePath); + } File.Move(torrentFile, processedPath); } }