Skip to content

Commit e281ba8

Browse files
authored
fix: lake: correct exe perms on restore (#14240)
This PR ensures executables are executable when restored from the Lake cache even if they were not originally executable in the cache (e.g., because they were downloaded through `lake cache get`). This is does not correct permissions for executables obtained from the cache without restoring them. However, building executables in the standard way (e.g., via `lean_exe` / `buildLeanExe`) should always restore them.
1 parent 009a063 commit e281ba8

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/lake/Lake/Build/Common.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,11 @@ public def restoreArtifact (file : FilePath) (art : Artifact) (exe := false) : L
657657
-- writing to such paths as this can corrupt the cache if the file was hard linked instead
658658
let r := {read := true, write := false, execution := exe}
659659
IO.setAccessRights file ⟨r, r, r⟩
660+
else if exe then
661+
-- Ensure restored executables are executable
662+
-- They may not have been if acquired through `lake cache get`
663+
let r := {read := true, write := false, execution := exe}
664+
IO.setAccessRights file ⟨r, r, r⟩
660665
logVerbose s!"restored artifact from cache to: {file}"
661666
writeFileHash file art.hash
662667
return art.useLocalFile file

tests/lake/tests/cache/test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,13 @@ test_restored +Module:olean.server Module.olean.server
329329
test_restored +Module:olean.private Module.olean.private
330330
test_restored +Module:ir Module.ir
331331

332+
# Verify that a hard linked restored executable is given the right
333+
# permissions to run even if the cached artifact lacked them (e.g.,
334+
# because it came from `lake cache get`)
335+
test_cmd chmod 444 $CACHE_DIR/artifacts/*
336+
test_cmd rm -rf .lake/build/bin
337+
test_run exe test
338+
332339
# Verify that invalid outputs do not break Lake
333340
if command -v jq > /dev/null; then # skip if no jq found
334341
libPath=$($LAKE query Test:static)

0 commit comments

Comments
 (0)