Don't timeout when ensuring a local FS entry is deleted

This commit is contained in:
Alex Barney 2020-05-30 17:27:51 -07:00
parent 2171f2ae21
commit a59dc611c2

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading;
using LibHac.Common; using LibHac.Common;
using LibHac.Fs; using LibHac.Fs;
@ -591,22 +592,28 @@ namespace LibHac.FsSystem
} }
// Delete operations on IFileSystem should be synchronous // Delete operations on IFileSystem should be synchronous
// DeleteFile and RemoveDirectory only mark the file for deletion, so we need // DeleteFile and RemoveDirectory only mark the file for deletion on Windows,
// to poll the filesystem until it's actually gone // so we need to poll the filesystem until it's actually gone
private static void EnsureDeleted(FileSystemInfo entry) private static void EnsureDeleted(FileSystemInfo entry)
{ {
int tries = 0; const int noDelayRetryCount = 1000;
const int retryDelay = 500;
do // The entry is usually deleted within the first 5-10 tries
for (int i = 0; i < noDelayRetryCount; i++)
{ {
entry.Refresh(); entry.Refresh();
tries++;
if (tries > 1000) if (!entry.Exists)
{ return;
throw new IOException($"Unable to delete file {entry.FullName}"); }
}
} while (entry.Exists); // Nintendo's solution is to check every 500 ms with no timeout
while (entry.Exists)
{
Thread.Sleep(retryDelay);
entry.Refresh();
}
} }
} }
} }