mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Properly catch exceptions in LocalFileSystem.CleanDirectoryRecursively
This commit is contained in:
parent
2793648d37
commit
6fe89a2966
1 changed files with 29 additions and 28 deletions
|
@ -336,35 +336,10 @@ namespace LibHac.FsSystem
|
||||||
Result rc = ResolveFullPath(out string fullPath, in path, true);
|
Result rc = ResolveFullPath(out string fullPath, in path, true);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
foreach (string file in Directory.EnumerateFiles(fullPath))
|
rc = GetDirInfo(out DirectoryInfo dir, fullPath);
|
||||||
{
|
|
||||||
rc = TargetLockedAvoidance.RetryToAvoidTargetLocked(
|
|
||||||
() =>
|
|
||||||
{
|
|
||||||
rc = GetFileInfo(out FileInfo fileInfo, file);
|
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
return DeleteFileInternal(fileInfo);
|
return CleanDirectoryInternal(dir, _fsClient);
|
||||||
}, _fsClient);
|
|
||||||
|
|
||||||
if (rc.IsFailure()) return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string dir in Directory.EnumerateDirectories(fullPath))
|
|
||||||
{
|
|
||||||
rc = TargetLockedAvoidance.RetryToAvoidTargetLocked(
|
|
||||||
() =>
|
|
||||||
{
|
|
||||||
rc = GetDirInfo(out DirectoryInfo dirInfo, dir);
|
|
||||||
if (rc.IsFailure()) return rc;
|
|
||||||
|
|
||||||
return DeleteDirectoryInternal(dirInfo, true);
|
|
||||||
}, _fsClient);
|
|
||||||
|
|
||||||
if (rc.IsFailure()) return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.Success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Result DoDeleteFile(in Path path)
|
protected override Result DoDeleteFile(in Path path)
|
||||||
|
@ -645,6 +620,32 @@ namespace LibHac.FsSystem
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Result CleanDirectoryInternal(DirectoryInfo dir, FileSystemClient fsClient)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (FileInfo fileInfo in dir.EnumerateFiles())
|
||||||
|
{
|
||||||
|
Result rc = TargetLockedAvoidance.RetryToAvoidTargetLocked(() => DeleteFileInternal(fileInfo),
|
||||||
|
fsClient);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (DirectoryInfo dirInfo in dir.EnumerateDirectories())
|
||||||
|
{
|
||||||
|
Result rc = TargetLockedAvoidance.RetryToAvoidTargetLocked(() => DeleteDirectoryInternal(dirInfo, true),
|
||||||
|
fsClient);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (ex.HResult < 0)
|
||||||
|
{
|
||||||
|
return HResult.HResultToHorizonResult(ex.HResult).Log();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
private static Result DeleteDirectoryInternal(DirectoryInfo dir, bool recursive)
|
private static Result DeleteDirectoryInternal(DirectoryInfo dir, bool recursive)
|
||||||
{
|
{
|
||||||
if (!dir.Exists)
|
if (!dir.Exists)
|
||||||
|
|
Loading…
Reference in a new issue