mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
Improve renaming of series folder within the same root folder
This commit is contained in:
parent
6fed932a61
commit
4bc0ffa74d
@ -227,6 +227,14 @@ public void MoveFile(string source, string destination, bool overwrite = false)
|
||||
MoveFileInternal(source, destination);
|
||||
}
|
||||
|
||||
public void MoveFolder(string source, string destination)
|
||||
{
|
||||
Ensure.That(source, () => source).IsValidPath();
|
||||
Ensure.That(destination, () => destination).IsValidPath();
|
||||
|
||||
Directory.Move(source, destination);
|
||||
}
|
||||
|
||||
protected virtual void MoveFileInternal(string source, string destination)
|
||||
{
|
||||
File.Move(source, destination);
|
||||
|
@ -28,6 +28,7 @@ public interface IDiskProvider
|
||||
void DeleteFile(string path);
|
||||
void CopyFile(string source, string destination, bool overwrite = false);
|
||||
void MoveFile(string source, string destination, bool overwrite = false);
|
||||
void MoveFolder(string source, string destination);
|
||||
bool TryCreateHardLink(string source, string destination);
|
||||
void DeleteFolder(string path, bool recursive);
|
||||
string ReadAllText(string filePath);
|
||||
|
@ -1,10 +1,12 @@
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Instrumentation.Extensions;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Tv.Commands;
|
||||
using NzbDrone.Core.Tv.Events;
|
||||
|
||||
@ -16,6 +18,7 @@ public class MoveSeriesService : IExecute<MoveSeriesCommand>, IExecute<BulkMoveS
|
||||
private readonly IBuildFileNames _filenameBuilder;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IDiskTransferService _diskTransferService;
|
||||
private readonly IRootFolderService _rootFolderService;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly Logger _logger;
|
||||
|
||||
@ -23,6 +26,7 @@ public MoveSeriesService(ISeriesService seriesService,
|
||||
IBuildFileNames filenameBuilder,
|
||||
IDiskProvider diskProvider,
|
||||
IDiskTransferService diskTransferService,
|
||||
IRootFolderService rootFolderService,
|
||||
IEventAggregator eventAggregator,
|
||||
Logger logger)
|
||||
{
|
||||
@ -30,6 +34,7 @@ public MoveSeriesService(ISeriesService seriesService,
|
||||
_filenameBuilder = filenameBuilder;
|
||||
_diskProvider = diskProvider;
|
||||
_diskTransferService = diskTransferService;
|
||||
_rootFolderService = rootFolderService;
|
||||
_eventAggregator = eventAggregator;
|
||||
_logger = logger;
|
||||
}
|
||||
@ -53,7 +58,18 @@ private void MoveSingleSeries(Series series, string sourcePath, string destinati
|
||||
|
||||
try
|
||||
{
|
||||
_diskTransferService.TransferFolder(sourcePath, destinationPath, TransferMode.Move);
|
||||
var sourceRootFolder = _rootFolderService.GetBestRootFolderPath(sourcePath);
|
||||
var destinationRootFolder = _rootFolderService.GetBestRootFolderPath(destinationPath);
|
||||
|
||||
if (sourceRootFolder.PathEquals(destinationRootFolder) && !_diskProvider.FolderExists(destinationPath))
|
||||
{
|
||||
_diskProvider.MoveFolder(sourcePath, destinationPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
_diskTransferService.TransferFolder(sourcePath, destinationPath, TransferMode.Move);
|
||||
}
|
||||
|
||||
_logger.ProgressInfo("{0} moved successfully to {1}", series.Title, series.Path);
|
||||
|
||||
_eventAggregator.PublishEvent(new SeriesMovedEvent(series, sourcePath, destinationPath));
|
||||
|
Loading…
Reference in New Issue
Block a user