@@ -453,13 +453,14 @@ public def Cache.saveArtifact
453453 let hash := Hash.ofString normalized
454454 let descr := artifactWithExt hash ext
455455 let cacheFile := cache.artifactDir / descr.relPath
456- createParentDirs cacheFile
457456 -- make the local file unwritable where possible to discourage users from
458457 -- writing to such paths as this can corrupt the cache if the file was hard linked
459458 let r := {read := true , write := false , execution := false }
460459 IO.setAccessRights file ⟨r, r, r⟩
461- IO.FS.writeFile cacheFile normalized
462- IO.setAccessRights cacheFile ⟨r, r, r⟩
460+ unless (← cacheFile.pathExists) do
461+ createParentDirs cacheFile
462+ IO.FS.writeFile cacheFile normalized
463+ IO.setAccessRights cacheFile ⟨r, r, r⟩
463464 writeFileHash file hash
464465 let mtime := (← getMTime cacheFile |>.toBaseIO).toOption.getD 0
465466 let path := if useLocalFile then file else cacheFile
@@ -469,14 +470,15 @@ public def Cache.saveArtifact
469470 let hash := Hash.ofByteArray contents
470471 let descr := artifactWithExt hash ext
471472 let cacheFile := cache.artifactDir / descr.relPath
472- createParentDirs cacheFile
473473 -- make the local file unwritable where possible to discourage users from
474474 -- writing to such paths as this can corrupt the cache if the file is hard linked
475475 let r := {read := true , write := false , execution := exe}
476476 IO.setAccessRights file ⟨r, r, r⟩
477- if let .error _ ← (IO.FS.hardLink file cacheFile).toBaseIO then
478- IO.FS.writeBinFile cacheFile contents
479- IO.setAccessRights cacheFile ⟨r, r, r⟩
477+ unless (← cacheFile.pathExists) do
478+ createParentDirs cacheFile
479+ if let .error _ ← (IO.FS.hardLink file cacheFile).toBaseIO then
480+ IO.FS.writeBinFile cacheFile contents
481+ IO.setAccessRights cacheFile ⟨r, r, r⟩
480482 writeFileHash file hash
481483 let mtime := (← getMTime cacheFile |>.toBaseIO).toOption.getD 0
482484 let path := if useLocalFile then file else cacheFile
0 commit comments