1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00

Fixed: Improve moving file to location where another one exists

This commit is contained in:
Kevin Richter 2022-08-07 20:52:54 +02:00 committed by GitHub
parent d6dff451e0
commit 8ab040f612
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -265,6 +265,11 @@ public void MoveFolder(string source, string destination)
protected virtual void MoveFileInternal(string source, string destination)
{
if (File.Exists(destination))
{
throw new FileAlreadyExistsException("File already exists", destination);
}
File.Move(source, destination);
}

View File

@ -0,0 +1,14 @@
using System;
namespace NzbDrone.Common.Disk
{
public class FileAlreadyExistsException : Exception
{
public string Filename { get; set; }
public FileAlreadyExistsException(string message, string filename) : base(message)
{
Filename = filename;
}
}
}

View File

@ -134,6 +134,10 @@ private List<RenamedEpisodeFile> RenameFiles(List<EpisodeFile> episodeFiles, Ser
_eventAggregator.PublishEvent(new EpisodeFileRenamedEvent(series, episodeFile, previousPath));
}
catch (FileAlreadyExistsException ex)
{
_logger.Warn("File not renamed, there is already a file at the destination: {0}", ex.Filename);
}
catch (SameFilenameException ex)
{
_logger.Debug("File not renamed, source and destination are the same: {0}", ex.Filename);