EpisodeFileMover updates episode file path after move

This commit is contained in:
Mark McDowall 2014-02-27 16:32:08 -08:00
parent 645d44bf8f
commit 7758db5324
5 changed files with 14 additions and 13 deletions

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
namespace NzbDrone.Core.MediaFiles
{
@ -10,7 +9,7 @@ namespace NzbDrone.Core.MediaFiles
OldFiles = new List<EpisodeFile>();
}
public String Path { get; set; }
public EpisodeFile EpisodeFile { get; set; }
public List<EpisodeFile> OldFiles { get; set; }
}
}

View File

@ -15,8 +15,8 @@ namespace NzbDrone.Core.MediaFiles
{
public interface IMoveEpisodeFiles
{
string MoveEpisodeFile(EpisodeFile episodeFile, Series series);
string MoveEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode);
EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, Series series);
EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode);
}
public class EpisodeFileMovingService : IMoveEpisodeFiles
@ -40,7 +40,7 @@ namespace NzbDrone.Core.MediaFiles
_logger = logger;
}
public string MoveEpisodeFile(EpisodeFile episodeFile, Series series)
public EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, Series series)
{
var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id);
var newFileName = _buildFileNames.BuildFilename(episodes, series, episodeFile);
@ -49,10 +49,10 @@ namespace NzbDrone.Core.MediaFiles
_logger.Trace("Renaming episode file: {0} to {1}", episodeFile, filePath);
MoveFile(episodeFile, series, filePath);
return filePath;
return episodeFile;
}
public string MoveEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode)
public EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode)
{
var newFileName = _buildFileNames.BuildFilename(localEpisode.Episodes, localEpisode.Series, episodeFile);
var filePath = _buildFileNames.BuildFilePath(localEpisode.Series, localEpisode.SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path));
@ -60,10 +60,10 @@ namespace NzbDrone.Core.MediaFiles
_logger.Trace("Moving episode file: {0} to {1}", episodeFile, filePath);
MoveFile(episodeFile, localEpisode.Series, filePath);
return filePath;
return episodeFile;
}
private void MoveFile(EpisodeFile episodeFile, Series series, string destinationFilename)
private EpisodeFile MoveFile(EpisodeFile episodeFile, Series series, string destinationFilename)
{
Ensure.That(episodeFile, () => episodeFile).IsNotNull();
Ensure.That(series,() => series).IsNotNull();
@ -94,6 +94,7 @@ namespace NzbDrone.Core.MediaFiles
_logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, destinationFilename);
_diskProvider.MoveFile(episodeFile.Path, destinationFilename);
episodeFile.Path = destinationFilename;
try
{
@ -141,6 +142,8 @@ namespace NzbDrone.Core.MediaFiles
{
SetPermissions(destinationFilename, _configService.FileChmod);
}
return episodeFile;
}
private void SetPermissions(string path, string permissions)

View File

@ -80,7 +80,6 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
{
episodeFile.SceneName = Path.GetFileNameWithoutExtension(localEpisode.Path.CleanFilePath());
var moveResult = _episodeFileUpgrader.UpgradeEpisodeFile(episodeFile, localEpisode);
episodeFile.Path = moveResult.Path;
oldFiles = moveResult.OldFiles;
}

View File

@ -116,7 +116,7 @@ namespace NzbDrone.Core.MediaFiles
try
{
_logger.Trace("Renaming episode file: {0}", episodeFile);
episodeFile.Path = _episodeFileMover.MoveEpisodeFile(episodeFile, series);
_episodeFileMover.MoveEpisodeFile(episodeFile, series);
_mediaFileService.Update(episodeFile);
renamed.Add(episodeFile);

View File

@ -54,7 +54,7 @@ namespace NzbDrone.Core.MediaFiles
_mediaFileService.Delete(file, true);
}
moveFileResult.Path = _episodeFileMover.MoveEpisodeFile(episodeFile, localEpisode);
moveFileResult.EpisodeFile = _episodeFileMover.MoveEpisodeFile(episodeFile, localEpisode);
return moveFileResult;
}