Skip to content

Commit 3308801

Browse files
committed
chore: fix removeFile on Windows
1 parent 3ad8567 commit 3308801

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

src/lake/Lake/Build/Module.lean

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -561,23 +561,29 @@ public def Module.depsFacetConfig : ModuleFacetConfig depsFacet :=
561561

562562
/-- Remove all existing artifacts produced by the Lean build of the module. -/
563563
public def Module.clearOutputArtifacts (mod : Module) : IO PUnit := do
564-
removeFileIfExists mod.oleanFile
565-
removeFileIfExists mod.oleanServerFile
566-
removeFileIfExists mod.oleanPrivateFile
567-
removeFileIfExists mod.ileanFile
568-
removeFileIfExists mod.irFile
569-
removeFileIfExists mod.cFile
570-
removeFileIfExists mod.bcFile
564+
try
565+
removeFileIfExists mod.oleanFile
566+
removeFileIfExists mod.oleanServerFile
567+
removeFileIfExists mod.oleanPrivateFile
568+
removeFileIfExists mod.ileanFile
569+
removeFileIfExists mod.irFile
570+
removeFileIfExists mod.cFile
571+
removeFileIfExists mod.bcFile
572+
catch e =>
573+
error s!"failed to remove output artifacts: {e}"
571574

572575
/-- Remove any cached file hashes of the module build outputs (in `.hash` files). -/
573576
public def Module.clearOutputHashes (mod : Module) : IO PUnit := do
574-
clearFileHash mod.oleanFile
575-
clearFileHash mod.oleanServerFile
576-
clearFileHash mod.oleanPrivateFile
577-
clearFileHash mod.ileanFile
578-
clearFileHash mod.irFile
579-
clearFileHash mod.cFile
580-
clearFileHash mod.bcFile
577+
try
578+
clearFileHash mod.oleanFile
579+
clearFileHash mod.oleanServerFile
580+
clearFileHash mod.oleanPrivateFile
581+
clearFileHash mod.ileanFile
582+
clearFileHash mod.irFile
583+
clearFileHash mod.cFile
584+
clearFileHash mod.bcFile
585+
catch e =>
586+
error s!"failed to remove output hashes: {e}"
581587

582588
/-- Cache the file hashes of the module build outputs in `.hash` files. -/
583589
public def Module.cacheOutputHashes (mod : Module) : IO PUnit := do

src/lake/Lake/Util/IO.lean

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,23 @@ namespace Lake
1616
public def createParentDirs (path : FilePath) : IO Unit := do
1717
if let some dir := path.parent then IO.FS.createDirAll dir
1818

19+
/--
20+
Remove the file at `path`.
21+
Also removes read-only files on Windows, unlike `IO.FS.removeFile`.
22+
-/
23+
def removeFile (path : FilePath) : IO Unit := do
24+
try IO.FS.removeFile path catch
25+
| e@(.permissionDenied ..) =>
26+
if Platform.isWindows then
27+
let rw := {read := true, write := true}
28+
IO.setAccessRights path ⟨rw, rw, rw⟩
29+
IO.FS.removeFile path
30+
else throw e
31+
| e => throw e
32+
1933
/-- Remove the file at `path` if it exists. -/
2034
public def removeFileIfExists (path : FilePath) : IO Unit := do
21-
try IO.FS.removeFile path catch
35+
try removeFile path catch
2236
| .noFileOrDirectory .. => pure ()
2337
| e => throw e
2438

tests/lake/tests/cache/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ source ../common.sh
77

88
# Store Lake cache in a local directory
99
TEST_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
10-
CACHE_DIR="$TEST_DIR/.lake/cache"
10+
CACHE_DIR="$(norm_path "$TEST_DIR")/.lake/cache"
1111
export LAKE_CACHE_DIR="$CACHE_DIR"
1212

1313
# Verify packages without `enableArtifactCache` do not use the cache by default

tests/lake/tests/common.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ else
4040
fi
4141

4242
if [ "$OS" = Windows_NT ]; then
43-
norm_dirname() { cygpath -u "$(dirname -- "$1")"; }
44-
else
45-
norm_dirname() { dirname -- "$1"; }
43+
norm_path() { cygpath -u "$1"; }
4644
fi
45+
norm_dirname() { norm_path "$(dirname -- "$1")"; }
4746

4847
init_git() {
4948
echo "# initialize test repository"

0 commit comments

Comments
 (0)