@@ -430,40 +430,52 @@ def find_cached_script(i):
430430
431431def fix_cache_paths (cached_path , env ):
432432
433- current_cache_path = cached_path
433+ current_cache_path = os . path . normpath ( cached_path )
434434
435435 new_env = env # just a reference
436436
437+ def normalize_and_replace_path (path_str ):
438+ """Helper to normalize and replace cache paths in a string."""
439+ # Normalize the path to use the current OS separators
440+ normalized = os .path .normpath (path_str )
441+
442+ # Check if path contains local/cache or local\cache pattern
443+ path_parts = normalized .split (os .sep )
444+
445+ try :
446+ local_idx = path_parts .index ("local" )
447+ if local_idx + \
448+ 1 < len (path_parts ) and path_parts [local_idx + 1 ] == "cache" :
449+ # Extract the loaded cache path (up to and including "cache")
450+ loaded_cache_path = os .sep .join (path_parts [:local_idx + 2 ])
451+ loaded_cache_path_norm = os .path .normpath (loaded_cache_path )
452+
453+ if loaded_cache_path_norm != current_cache_path and os .path .exists (
454+ current_cache_path ):
455+ # Replace old cache path with current cache path
456+ return normalized .replace (
457+ loaded_cache_path_norm , current_cache_path )
458+ except (ValueError , IndexError ):
459+ # "local" not in path or malformed path
460+ pass
461+
462+ return normalized
463+
437464 for key , val in new_env .items ():
438- # Check for a path separator in a string and determine the
439- # separator
440- if isinstance (val , str ) and any (sep in val for sep in [
441- "/local/cache/" , "\\ local\\ cache\\ " ]):
442- sep = "/" if "/local/cache/" in val else "\\ "
443-
444- path_split = val .split (sep )
445- repo_entry_index = path_split .index ("local" )
446- loaded_cache_path = sep .join (
447- path_split [0 :repo_entry_index + 2 ])
448- if loaded_cache_path != current_cache_path and os .path .exists (
449- current_cache_path ):
450- new_env [key ] = val .replace (
451- loaded_cache_path , current_cache_path ).replace (sep , "/" )
465+ if isinstance (val , str ):
466+ # Check if path contains cache directory pattern
467+ normalized_val = val .replace ('\\ ' , os .sep ).replace ('/' , os .sep )
468+ if os .sep .join (['local' , 'cache' ]) in normalized_val :
469+ new_env [key ] = normalize_and_replace_path (val )
452470
453471 elif isinstance (val , list ):
454472 for i , val2 in enumerate (val ):
455- if isinstance (val2 , str ) and any (sep in val2 for sep in [
456- "/local/cache/" , "\\ local\\ cache\\ " ]):
457- sep = "/" if "/local/cache/" in val2 else "\\ "
458-
459- path_split = val2 .split (sep )
460- repo_entry_index = path_split .index ("local" )
461- loaded_cache_path = sep .join (
462- path_split [0 :repo_entry_index + 2 ])
463- if loaded_cache_path != current_cache_path and os .path .exists (
464- current_cache_path ):
465- new_env [key ][i ] = val2 .replace (
466- loaded_cache_path , current_cache_path ).replace (sep , "/" )
473+ if isinstance (val2 , str ):
474+ # Check if path contains cache directory pattern
475+ normalized_val2 = val2 .replace (
476+ '\\ ' , os .sep ).replace ('/' , os .sep )
477+ if os .sep .join (['local' , 'cache' ]) in normalized_val2 :
478+ new_env [key ][i ] = normalize_and_replace_path (val2 )
467479
468480 return {'return' : 0 , 'new_env' : new_env }
469481
0 commit comments