New: Remove empty subfolders after renaming FileSetLastWriteTime
Closes #490
This commit is contained in:
parent
1603b06431
commit
1a5eafd2b1
|
@ -418,5 +418,19 @@ namespace NzbDrone.Common.Disk
|
||||||
|
|
||||||
return di.GetFiles().ToList();
|
return di.GetFiles().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RemoveEmptySubfolders(string path)
|
||||||
|
{
|
||||||
|
var subfolders = GetDirectories(path);
|
||||||
|
var files = GetFiles(path, SearchOption.AllDirectories);
|
||||||
|
|
||||||
|
foreach (var subfolder in subfolders)
|
||||||
|
{
|
||||||
|
if (files.None(f => subfolder.IsParentPath(f)))
|
||||||
|
{
|
||||||
|
DeleteFolder(path, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,5 +47,6 @@ namespace NzbDrone.Common.Disk
|
||||||
IMount GetMount(string path);
|
IMount GetMount(string path);
|
||||||
List<DirectoryInfo> GetDirectoryInfos(string path);
|
List<DirectoryInfo> GetDirectoryInfos(string path);
|
||||||
List<FileInfo> GetFileInfos(string path);
|
List<FileInfo> GetFileInfos(string path);
|
||||||
|
void RemoveEmptySubfolders(string path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Common.Instrumentation.Extensions;
|
using NzbDrone.Common.Instrumentation.Extensions;
|
||||||
using NzbDrone.Core.MediaFiles.Commands;
|
using NzbDrone.Core.MediaFiles.Commands;
|
||||||
|
@ -30,6 +31,7 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
private readonly IEpisodeService _episodeService;
|
private readonly IEpisodeService _episodeService;
|
||||||
private readonly IBuildFileNames _filenameBuilder;
|
private readonly IBuildFileNames _filenameBuilder;
|
||||||
|
private readonly IDiskProvider _diskProvider;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public RenameEpisodeFileService(ISeriesService seriesService,
|
public RenameEpisodeFileService(ISeriesService seriesService,
|
||||||
|
@ -38,6 +40,7 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
IEventAggregator eventAggregator,
|
IEventAggregator eventAggregator,
|
||||||
IEpisodeService episodeService,
|
IEpisodeService episodeService,
|
||||||
IBuildFileNames filenameBuilder,
|
IBuildFileNames filenameBuilder,
|
||||||
|
IDiskProvider diskProvider,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_seriesService = seriesService;
|
_seriesService = seriesService;
|
||||||
|
@ -46,6 +49,7 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
_episodeService = episodeService;
|
_episodeService = episodeService;
|
||||||
_filenameBuilder = filenameBuilder;
|
_filenameBuilder = filenameBuilder;
|
||||||
|
_diskProvider = diskProvider;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +138,8 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
|
|
||||||
if (renamed.Any())
|
if (renamed.Any())
|
||||||
{
|
{
|
||||||
|
_diskProvider.RemoveEmptySubfolders(series.Path);
|
||||||
|
|
||||||
_eventAggregator.PublishEvent(new SeriesRenamedEvent(series));
|
_eventAggregator.PublishEvent(new SeriesRenamedEvent(series));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue