[fix] 修复BashUtil.RemoveDir在偶然情况下出现删除目录失败的问题。新增多次重试。

main
walon 2023-11-01 19:36:42 +08:00
parent d9ed27abfb
commit d5b52cc8db
1 changed files with 16 additions and 8 deletions

View File

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace HybridCLR.Editor.Installer
@ -67,16 +68,23 @@ namespace HybridCLR.Editor.Installer
{
return;
}
foreach (var file in Directory.GetFiles(dir))
int maxTryCount = 5;
for (int i = 0; i < maxTryCount; ++i)
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}
foreach (var subDir in Directory.GetDirectories(dir))
try
{
RemoveDir(subDir);
if (Directory.Exists(dir))
{
Directory.Delete(dir, true);
}
}
catch (Exception e)
{
UnityEngine.Debug.LogError($"[BashUtil] RemoveDir:{dir} with exception:{e}. try count:{i}");
Thread.Sleep(100);
}
}
Directory.Delete(dir);
}
public static void RecreateDir(string dir)