mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-19 07:52:33 +02:00
Throw when unable to move file
This commit is contained in:
parent
2a44cab543
commit
44772c7391
@ -80,6 +80,10 @@ public void should_not_publish_event_if_no_files_are_renamed()
|
|||||||
{
|
{
|
||||||
GivenEpisodeFiles();
|
GivenEpisodeFiles();
|
||||||
|
|
||||||
|
Mocker.GetMock<IMoveEpisodeFiles>()
|
||||||
|
.Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), It.IsAny<Series>()))
|
||||||
|
.Throws(new SameFilenameException("Same file name", "Filename"));
|
||||||
|
|
||||||
Subject.Execute(new RenameSeriesCommand(_series.Id));
|
Subject.Execute(new RenameSeriesCommand(_series.Id));
|
||||||
|
|
||||||
Mocker.GetMock<IMessageAggregator>()
|
Mocker.GetMock<IMessageAggregator>()
|
||||||
|
@ -62,15 +62,12 @@ private EpisodeFile MoveFile(EpisodeFile episodeFile, string destinationFilename
|
|||||||
{
|
{
|
||||||
if (!_diskProvider.FileExists(episodeFile.Path))
|
if (!_diskProvider.FileExists(episodeFile.Path))
|
||||||
{
|
{
|
||||||
_logger.Error("Episode file path does not exist, {0}", episodeFile.Path);
|
throw new FileNotFoundException("Episode file path does not exist", episodeFile.Path);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Only rename if existing and new filenames don't match
|
|
||||||
if (DiskProvider.PathEquals(episodeFile.Path, destinationFilename))
|
if (DiskProvider.PathEquals(episodeFile.Path, destinationFilename))
|
||||||
{
|
{
|
||||||
_logger.Debug("Skipping file rename, source and destination are the same: {0}", episodeFile.Path);
|
throw new SameFilenameException("File not moved, source and destination are the same", episodeFile.Path);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_diskProvider.CreateFolder(new FileInfo(destinationFilename).DirectoryName);
|
_diskProvider.CreateFolder(new FileInfo(destinationFilename).DirectoryName);
|
||||||
|
@ -68,13 +68,6 @@ public List<ImportDecision> Import(List<ImportDecision> decisions, bool newDownl
|
|||||||
if (newDownload)
|
if (newDownload)
|
||||||
{
|
{
|
||||||
episodeFile = _episodeFileUpgrader.UpgradeEpisodeFile(episodeFile, localEpisode);
|
episodeFile = _episodeFileUpgrader.UpgradeEpisodeFile(episodeFile, localEpisode);
|
||||||
|
|
||||||
if (episodeFile == null)
|
|
||||||
{
|
|
||||||
_logger.Error("Failed to move [{0}], aborting processing", localEpisode);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
_messageAggregator.PublishEvent(new EpisodeImportedEvent(episodeFile));
|
_messageAggregator.PublishEvent(new EpisodeImportedEvent(episodeFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Messaging;
|
using NzbDrone.Common.Messaging;
|
||||||
@ -34,20 +35,28 @@ private void RenameFiles(List<EpisodeFile> episodeFiles, Series series)
|
|||||||
var renamed = new List<EpisodeFile>();
|
var renamed = new List<EpisodeFile>();
|
||||||
|
|
||||||
foreach (var file in episodeFiles)
|
foreach (var file in episodeFiles)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var episodeFile = file;
|
var episodeFile = file;
|
||||||
|
|
||||||
_logger.Trace("Renaming episode file: {0}", episodeFile);
|
_logger.Trace("Renaming episode file: {0}", episodeFile);
|
||||||
episodeFile = _episodeFileMover.MoveEpisodeFile(episodeFile, series);
|
episodeFile = _episodeFileMover.MoveEpisodeFile(episodeFile, series);
|
||||||
|
|
||||||
if (episodeFile != null)
|
|
||||||
{
|
|
||||||
_mediaFileService.Update(episodeFile);
|
_mediaFileService.Update(episodeFile);
|
||||||
renamed.Add(episodeFile);
|
renamed.Add(episodeFile);
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Trace("Renamed episode file: {0}", episodeFile);
|
_logger.Trace("Renamed episode file: {0}", episodeFile);
|
||||||
}
|
}
|
||||||
|
catch (SameFilenameException ex)
|
||||||
|
{
|
||||||
|
_logger.Trace("File not renamed, source and destination are the same: {0}", ex.Filename);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Failed to rename file: " + file.Path, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (renamed.Any())
|
if (renamed.Any())
|
||||||
{
|
{
|
||||||
|
14
NzbDrone.Core/MediaFiles/SameFilenameException.cs
Normal file
14
NzbDrone.Core/MediaFiles/SameFilenameException.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.MediaFiles
|
||||||
|
{
|
||||||
|
public class SameFilenameException : Exception
|
||||||
|
{
|
||||||
|
public String Filename { get; set; }
|
||||||
|
|
||||||
|
public SameFilenameException(string message, string filename) : base(message)
|
||||||
|
{
|
||||||
|
Filename = filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -234,6 +234,7 @@
|
|||||||
<Compile Include="Download\EpisodeGrabbedEvent.cs" />
|
<Compile Include="Download\EpisodeGrabbedEvent.cs" />
|
||||||
<Compile Include="MediaFiles\Events\SeriesRenamedEvent.cs" />
|
<Compile Include="MediaFiles\Events\SeriesRenamedEvent.cs" />
|
||||||
<Compile Include="MediaFiles\RenameEpisodeFileService.cs" />
|
<Compile Include="MediaFiles\RenameEpisodeFileService.cs" />
|
||||||
|
<Compile Include="MediaFiles\SameFilenameException.cs" />
|
||||||
<Compile Include="MediaFiles\UpgradeMediaFileService.cs" />
|
<Compile Include="MediaFiles\UpgradeMediaFileService.cs" />
|
||||||
<Compile Include="MetadataSource\Trakt\TraktCommunicationException.cs" />
|
<Compile Include="MetadataSource\Trakt\TraktCommunicationException.cs" />
|
||||||
<Compile Include="Notifications\Email\TestEmailCommand.cs" />
|
<Compile Include="Notifications\Email\TestEmailCommand.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user