龙腾猫跃 před 5 měsíci
rodič
revize
27e650d698

+ 2 - 1
Shared/Utils/DirectoryUtils.cs

@@ -103,7 +103,8 @@ public static class DirectoryUtils {
             // 同一磁盘剪切,直接调用 Move(这只修改文件夹名,效率更高)
             Logger.Trace($"剪切文件夹到同一磁盘:{sourceFolder} → {destFolder}");
             DirectoryUtils.Delete(destFolder); // Move 要求此前不存在对应文件夹
-            Directory.Move(PathUtils.ForApi(sourceFolder), PathUtils.ForApi(destFolder));
+            ResilientUtils.RetryOn<IOException>(() 
+                => Directory.Move(PathUtils.ForApi(sourceFolder), PathUtils.ForApi(destFolder)));
         } else {
             // 不同磁盘,必须先复制再删除,这就是我们傻逼微软
             Logger.Trace($"剪切文件夹到不同磁盘:{sourceFolder} → {destFolder}");

+ 2 - 2
Shared/Utils/ResilientUtils.cs

@@ -2,7 +2,7 @@
 public static class ResilientUtils {
 
     /// <summary>
-    /// 在抛出异常时,延迟并自动重试。
+    /// 在抛出任意异常时,延迟并自动重试。
     /// </summary>
     public static void Retry(Action action, int maxAttempts = 2, int delayMs = 200, [CallerMemberName] string caller = "")
         => RetryOn<Exception>(action, maxAttempts, delayMs, caller);
@@ -13,7 +13,7 @@ public static class ResilientUtils {
         => RetryOn<TException, object?>(() => { action(); return null; }, maxAttempts, delayMs, caller);
 
     /// <summary>
-    /// 在抛出异常时,延迟并自动重试。
+    /// 在抛出任意异常时,延迟并自动重试。
     /// </summary>
     public static void Retry<TOut>(Func<TOut> func, int maxAttempts = 2, int delayMs = 200, [CallerMemberName] string caller = "")
         => RetryOn<Exception, TOut>(func, maxAttempts, delayMs, caller);