Skip to content

Commit

Permalink
fix(subst): ignore broken symlinks
Browse files Browse the repository at this point in the history
Fixes ocaml#9593

Signed-off-by: Etienne Millon <[email protected]>
  • Loading branch information
emillon committed Jan 23, 2024
1 parent 7f770e0 commit d04f6bf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
43 changes: 26 additions & 17 deletions bin/subst.ml
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
open Import

let is_a_source_file path =
(match Path.extension path with
| ".flv"
| ".gif"
| ".ico"
| ".jpeg"
| ".jpg"
| ".mov"
| ".mp3"
| ".mp4"
| ".otf"
| ".pdf"
| ".png"
| ".ttf"
| ".woff" -> false
| _ -> true)
&& (Path.stat_exn path).st_kind = Unix.S_REG
let is_path_a_source_file path =
match Path.extension path with
| ".flv"
| ".gif"
| ".ico"
| ".jpeg"
| ".jpg"
| ".mov"
| ".mp3"
| ".mp4"
| ".otf"
| ".pdf"
| ".png"
| ".ttf"
| ".woff" -> false
| _ -> true
;;

let is_kind_a_source_file path =
match Path.stat_exn path with
| st -> st.st_kind = Unix.S_REG
| exception Unix.Unix_error (ENOENT, "stat", _) ->
(* broken symlink *)
false
;;

let is_a_source_file path = is_path_a_source_file path && is_kind_a_source_file path

let subst_string s path ~map =
let len = String.length s in
let longest_var = String.longest (String.Map.keys map) in
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/9810.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- subst: ignore broken symlinks when looking at source files
(#9810, fixes #9593, @emillon)
2 changes: 0 additions & 2 deletions test/blackbox-tests/test-cases/subst/broken-symlink.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ This test requires a git repository, otherwise `dune subst` does nothing.
create mode 100644 dune-project

$ dune subst
Error: stat(broken): No such file or directory
[1]

0 comments on commit d04f6bf

Please sign in to comment.