@@ -15,7 +15,7 @@ namespace LLMUnity
1515 public class LLMBuilder : AssetPostprocessor
1616 {
1717 static List < StringPair > movedPairs = new List < StringPair > ( ) ;
18- public static string BuildTempDir = Path . Combine ( Application . temporaryCachePath , "LLMUnityBuild" ) ;
18+ public static string BuildTempDir = Path . Combine ( Directory . GetParent ( Application . dataPath ) . FullName , "LLMUnityBuild" ) ;
1919 static string movedCache = Path . Combine ( BuildTempDir , "moved.json" ) ;
2020
2121 [ InitializeOnLoadMethod ]
@@ -36,6 +36,28 @@ public static string PluginLibraryDir(string platform, bool relative = false)
3636 return Path . Combine ( PluginDir ( platform , relative ) , LLMUnitySetup . libraryName ) ;
3737 }
3838
39+ public static void Retry ( System . Action action , int retries = 10 , int delayMs = 100 )
40+ {
41+ for ( int i = 0 ; i < retries ; i ++ )
42+ {
43+ try
44+ {
45+ action ( ) ;
46+ return ;
47+ }
48+ catch ( IOException )
49+ {
50+ if ( i == retries - 1 ) throw ;
51+ System . Threading . Thread . Sleep ( delayMs ) ;
52+ }
53+ catch ( System . UnauthorizedAccessException )
54+ {
55+ if ( i == retries - 1 ) throw ;
56+ System . Threading . Thread . Sleep ( delayMs ) ;
57+ }
58+ }
59+ }
60+
3961 /// <summary>
4062 /// Performs an action for a file or a directory recursively
4163 /// </summary>
@@ -46,7 +68,7 @@ public static void HandleActionFileRecursive(string source, string target, Actio
4668 {
4769 if ( File . Exists ( source ) )
4870 {
49- actionCallback ( source , target ) ;
71+ Retry ( ( ) => actionCallback ( source , target ) ) ;
5072 }
5173 else if ( Directory . Exists ( source ) )
5274 {
@@ -106,8 +128,8 @@ public static bool DeletePath(string path)
106128 LLMUnitySetup . LogError ( $ "Safeguard: { path } will not be deleted because it may not be safe") ;
107129 return false ;
108130 }
109- if ( File . Exists ( path ) ) File . Delete ( path ) ;
110- else if ( Directory . Exists ( path ) ) Directory . Delete ( path , true ) ;
131+ if ( File . Exists ( path ) ) Retry ( ( ) => File . Delete ( path ) ) ;
132+ else if ( Directory . Exists ( path ) ) Retry ( ( ) => Directory . Delete ( path , true ) ) ;
111133 return true ;
112134 }
113135
@@ -300,8 +322,21 @@ public static void Reset()
300322 bool refresh = false ;
301323 foreach ( var pair in movedPairs )
302324 {
303- if ( pair . source == "" ) refresh |= DeletePath ( pair . target ) ;
304- else refresh |= MoveAction ( pair . target , pair . source , false ) ;
325+ if ( pair . source == "" )
326+ {
327+ refresh |= DeletePath ( pair . target ) ;
328+ }
329+ else
330+ {
331+ if ( File . Exists ( pair . source ) || Directory . Exists ( pair . source ) )
332+ {
333+ refresh |= DeletePath ( pair . target ) ;
334+ }
335+ else
336+ {
337+ refresh |= MoveAction ( pair . target , pair . source , false ) ;
338+ }
339+ }
305340 }
306341 if ( refresh ) AssetDatabase . Refresh ( ) ;
307342 DeletePath ( movedCache ) ;
0 commit comments