mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
Fixed: Improve moving file to location where another one exists
Closes #2884
This commit is contained in:
parent
0fc2e0a9ac
commit
db00ff1757
3 changed files with 24 additions and 0 deletions
|
@ -278,6 +278,11 @@ namespace NzbDrone.Common.Disk
|
||||||
|
|
||||||
protected virtual void MoveFileInternal(string source, string destination)
|
protected virtual void MoveFileInternal(string source, string destination)
|
||||||
{
|
{
|
||||||
|
if (File.Exists(destination))
|
||||||
|
{
|
||||||
|
throw new FileAlreadyExistsException("File already exists", destination);
|
||||||
|
}
|
||||||
|
|
||||||
_fileSystem.File.Move(source, destination);
|
_fileSystem.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -135,6 +135,10 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
|
|
||||||
_eventAggregator.PublishEvent(new TrackFileRenamedEvent(artist, trackFile, previousPath));
|
_eventAggregator.PublishEvent(new TrackFileRenamedEvent(artist, trackFile, previousPath));
|
||||||
}
|
}
|
||||||
|
catch (FileAlreadyExistsException ex)
|
||||||
|
{
|
||||||
|
_logger.Warn("File not renamed, there is already a file at the destination: {0}", ex.Filename);
|
||||||
|
}
|
||||||
catch (SameFilenameException ex)
|
catch (SameFilenameException ex)
|
||||||
{
|
{
|
||||||
_logger.Debug("File not renamed, source and destination are the same: {0}", ex.Filename);
|
_logger.Debug("File not renamed, source and destination are the same: {0}", ex.Filename);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue