diff --git a/src/NzbDrone.Common/Disk/DiskProviderBase.cs b/src/NzbDrone.Common/Disk/DiskProviderBase.cs index bbcfc618f4..ad5eb395fa 100644 --- a/src/NzbDrone.Common/Disk/DiskProviderBase.cs +++ b/src/NzbDrone.Common/Disk/DiskProviderBase.cs @@ -264,6 +264,11 @@ public void MoveFolder(string source, string destination, bool overwrite = false protected virtual void MoveFileInternal(string source, string destination) { + if (File.Exists(destination)) + { + throw new FileAlreadyExistsException("File already exists", destination); + } + File.Move(source, destination); } diff --git a/src/NzbDrone.Common/Disk/FileAlreadyExistsException.cs b/src/NzbDrone.Common/Disk/FileAlreadyExistsException.cs new file mode 100644 index 0000000000..69acb4cd7f --- /dev/null +++ b/src/NzbDrone.Common/Disk/FileAlreadyExistsException.cs @@ -0,0 +1,15 @@ +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; + } + } +} diff --git a/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs b/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs index 71219a955d..2140a56ede 100644 --- a/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs +++ b/src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs @@ -107,6 +107,10 @@ private List RenameFiles(List movieFiles, Movie mov _eventAggregator.PublishEvent(new MovieFileRenamedEvent(movie, movieFile, 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);