mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-05 20:42:19 -07:00
Fixed: Deleting artist folder fails when files/folders aren't instantly removed
(cherry picked from commit c84699ed5d5a2f59f236c26a8999d25a1102ec02)
This commit is contained in:
parent
099d19a04d
commit
c28a97cafd
1 changed files with 20 additions and 2 deletions
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.EnsureThat;
|
using NzbDrone.Common.EnsureThat;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
@ -306,9 +307,26 @@ namespace NzbDrone.Common.Disk
|
||||||
{
|
{
|
||||||
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
||||||
|
|
||||||
var files = GetFiles(path, recursive);
|
var files = GetFiles(path, recursive).ToList();
|
||||||
|
|
||||||
files.ToList().ForEach(RemoveReadOnly);
|
files.ForEach(RemoveReadOnly);
|
||||||
|
|
||||||
|
var attempts = 0;
|
||||||
|
|
||||||
|
while (attempts < 3 && files.Any())
|
||||||
|
{
|
||||||
|
EmptyFolder(path);
|
||||||
|
|
||||||
|
if (GetFiles(path, recursive).Any())
|
||||||
|
{
|
||||||
|
// Wait for IO operations to complete after emptying the folder since they aren't always
|
||||||
|
// instantly removed and it can lead to false positives that files are still present.
|
||||||
|
Thread.Sleep(3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
attempts++;
|
||||||
|
files = GetFiles(path, recursive).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
_fileSystem.Directory.Delete(path, recursive);
|
_fileSystem.Directory.Delete(path, recursive);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue