Delete file if exists when copying to {error,processed}StorePath (watch folder)

This commit is contained in:
Cucumberrbob 2025-02-17 23:03:38 +00:00
parent fe241db5db
commit c43be84507
No known key found for this signature in database
GPG key ID: 2B935C47401C3614

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);
}
}