mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-04-20 22:14:34 -04:00
Fixed recursion issue when emptying recycle bin
This commit is contained in:
@@ -146,7 +146,7 @@ namespace NzbDrone.Common.Disk
|
||||
{
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
||||
return Directory.EnumerateDirectories(path).Empty();
|
||||
return Directory.EnumerateFileSystemEntries(path).Empty();
|
||||
}
|
||||
|
||||
public string[] GetDirectories(string path)
|
||||
@@ -526,14 +526,21 @@ namespace NzbDrone.Common.Disk
|
||||
|
||||
public void RemoveEmptySubfolders(string path)
|
||||
{
|
||||
var subfolders = GetDirectories(path);
|
||||
var files = GetFiles(path, SearchOption.AllDirectories);
|
||||
|
||||
foreach (var subfolder in subfolders)
|
||||
// Depth first search for empty subdirectories
|
||||
foreach (var subdir in Directory.EnumerateDirectories(path))
|
||||
{
|
||||
if (files.None(f => subfolder.IsParentPath(f)))
|
||||
RemoveEmptySubfolders(subdir);
|
||||
|
||||
if (Directory.EnumerateFileSystemEntries(subdir).Empty())
|
||||
{
|
||||
DeleteFolder(subfolder, false);
|
||||
try
|
||||
{
|
||||
Directory.Delete(subdir, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Warn(ex, "Failed to remove empty directory {0}", subdir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user