From 754971e396c76b662f327d0258abcab6eff6649e Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Thu, 23 Nov 2023 13:17:08 -0600 Subject: [PATCH] fix: copy sandboxes should copy symlinks as well Signed-off-by: Rudi Grinberg --- doc/changes/9282.md | 1 + src/dune_engine/sandbox.ml | 8 ++++++++ .../test-cases/directory-targets/copy-sandboxing.t | 10 +--------- 3 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 doc/changes/9282.md diff --git a/doc/changes/9282.md b/doc/changes/9282.md new file mode 100644 index 00000000000..e7d31298f6d --- /dev/null +++ b/doc/changes/9282.md @@ -0,0 +1 @@ +- Copying mode for sandboxes will now follow symbolic links (#9282, @rgrinberg) diff --git a/src/dune_engine/sandbox.ml b/src/dune_engine/sandbox.ml index 2866030c4f1..7813ce7e92c 100644 --- a/src/dune_engine/sandbox.ml +++ b/src/dune_engine/sandbox.ml @@ -45,6 +45,7 @@ module Item = struct type t = | File | Directory of { perms : int } + | Link | Other of Unix.file_kind let of_path path = @@ -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 @@ -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 diff --git a/test/blackbox-tests/test-cases/directory-targets/copy-sandboxing.t b/test/blackbox-tests/test-cases/directory-targets/copy-sandboxing.t index 57459b98774..086d9bd26b1 100644 --- a/test/blackbox-tests/test-cases/directory-targets/copy-sandboxing.t +++ b/test/blackbox-tests/test-cases/directory-targets/copy-sandboxing.t @@ -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: