mirror of
https://github.com/Radarr/Radarr.git
synced 2024-10-03 22:57:18 +02:00
Fixed: Improve moving file to location where another one exists
Fixes #7460 (cherry picked from commit 8ab040f612ee04dac4813a08cdeaddd446a64dc9)
This commit is contained in:
parent
7c6858ecfb
commit
b1f0b2c216
@ -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);
|
||||
}
|
||||
|
||||
|
15
src/NzbDrone.Common/Disk/FileAlreadyExistsException.cs
Normal file
15
src/NzbDrone.Common/Disk/FileAlreadyExistsException.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -107,6 +107,10 @@ private List<RenamedMovieFile> RenameFiles(List<MovieFile> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user