Skip to content

Commit

Permalink
fix: copy sandboxes should copy symlinks as well
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>

<!-- ps-id: fac470a3-c036-414e-96ae-8aeb71153855 -->
  • Loading branch information
rgrinberg committed Nov 28, 2023
1 parent f140a17 commit 754971e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions doc/changes/9282.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Copying mode for sandboxes will now follow symbolic links (#9282, @rgrinberg)
8 changes: 8 additions & 0 deletions src/dune_engine/sandbox.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module Item = struct
type t =
| File
| Directory of { perms : int }
| Link
| Other of Unix.file_kind

let of_path path =
Expand All @@ -59,6 +60,7 @@ module Item = struct
match kind with
| S_DIR -> Directory { perms = (Path.Untracked.stat_exn path).st_perm }
| S_REG -> File
| S_LNK -> Link
| _ -> Other kind
;;
end
Expand All @@ -71,6 +73,12 @@ let copy_recursively =
in
let rec loop item ~src ~dst =
match (item : Item.t) with
| Link ->
(match Path.Untracked.stat_exn src with
| { Unix.st_kind = S_REG; _ } -> Io.copy_file ~chmod:chmod_file ~src ~dst ()
| { Unix.st_kind = S_DIR; st_perm = perms; _ } ->
loop (Directory { perms }) ~src ~dst
| { Unix.st_kind; _ } -> loop (Other st_kind) ~src ~dst)
| File -> Io.copy_file ~chmod:chmod_file ~src ~dst ()
| Directory { perms } ->
(match Path.Untracked.readdir_unsorted_with_kinds src with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,7 @@ Now we demonstrate that symlinks aren't supported:
> }
$ runtest "touch foo && ln -s foo bar"
File "dune", line 1, characters 0-63:
1 | (rule
2 | (alias foo)
3 | (action (echo test))
4 | (deps sub/targetdir))
Error: Failed to copy file _build/default/sub/targetdir/bar of kind "symbolic
link" while creating a copy sandbox
Hint: Re-run Dune to delete the stale artifact, or manually delete this file
[1]
test
$ runtest "mkdir bar && touch bar/somefileinbar && ln -s bar symlinktobar"
File "sub/dune", line 1, characters 0-151:
Expand Down

0 comments on commit 754971e

Please sign in to comment.