New: Remove empty subfolders after renaming FileSetLastWriteTime

Closes #490
pull/923/merge
Mark McDowall 9 years ago
parent 1603b06431
commit 1a5eafd2b1

@ -418,5 +418,19 @@ namespace NzbDrone.Common.Disk
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);
List<DirectoryInfo> GetDirectoryInfos(string path);
List<FileInfo> GetFileInfos(string path);
void RemoveEmptySubfolders(string path);
}
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.MediaFiles.Commands;
@ -30,6 +31,7 @@ namespace NzbDrone.Core.MediaFiles
private readonly IEventAggregator _eventAggregator;
private readonly IEpisodeService _episodeService;
private readonly IBuildFileNames _filenameBuilder;
private readonly IDiskProvider _diskProvider;
private readonly Logger _logger;
public RenameEpisodeFileService(ISeriesService seriesService,
@ -38,6 +40,7 @@ namespace NzbDrone.Core.MediaFiles
IEventAggregator eventAggregator,
IEpisodeService episodeService,
IBuildFileNames filenameBuilder,
IDiskProvider diskProvider,
Logger logger)
{
_seriesService = seriesService;
@ -46,6 +49,7 @@ namespace NzbDrone.Core.MediaFiles
_eventAggregator = eventAggregator;
_episodeService = episodeService;
_filenameBuilder = filenameBuilder;
_diskProvider = diskProvider;
_logger = logger;
}
@ -134,6 +138,8 @@ namespace NzbDrone.Core.MediaFiles
if (renamed.Any())
{
_diskProvider.RemoveEmptySubfolders(series.Path);
_eventAggregator.PublishEvent(new SeriesRenamedEvent(series));
}
}

Loading…
Cancel
Save