Merge pull request #707 from Cucumberrbob/fix/existing-file-in-error-processed-watch-path

Delete file if exists when copying to `Error Path` or `Processed Path` (watch folder)
This commit is contained in:
Roger Far 2025-02-23 11:23:07 -07:00 committed by GitHub
commit f0310e2b00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -107,12 +107,22 @@ public class WatchFolderChecker(ILogger<WatchFolderChecker> 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<WatchFolderChecker> 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);
}
}