@@ -91,11 +91,13 @@ let file_with_executable_bit ~executable path =
9191module Stats_for_digest = struct
9292 type t =
9393 { st_kind : Unix .file_kind
94- ; st_perm : Unix .file_perm
94+ ; executable : bool
9595 }
9696
9797 let of_unix_stats (stats : Unix.stats ) =
98- { st_kind = stats.st_kind; st_perm = stats.st_perm }
98+ (* Check if any of the +x bits are set, ignore read and write *)
99+ let executable = 0o111 land stats.st_perm <> 0 in
100+ { st_kind = stats.st_kind; executable }
99101 ;;
100102end
101103
@@ -113,17 +115,15 @@ let path_with_stats ~allow_dirs path (stats : Stats_for_digest.t) =
113115 let rec loop path (stats : Stats_for_digest.t ) =
114116 match stats.st_kind with
115117 | S_LNK ->
116- let executable = Path.Permissions. test Path.Permissions. execute stats.st_perm in
117118 Dune_filesystem_stubs.Unix_error.Detailed. catch
118119 (fun path ->
119120 let contents = Unix. readlink (Path. to_string path) in
120- path_with_executable_bit ~executable ~content_digest: contents)
121+ path_with_executable_bit ~executable: stats.executable ~content_digest: contents)
121122 path
122123 |> Result. map_error ~f: (fun x -> Path_digest_error. Unix_error x)
123124 | S_REG ->
124- let executable = Path.Permissions. test Path.Permissions. execute stats.st_perm in
125125 Dune_filesystem_stubs.Unix_error.Detailed. catch
126- (file_with_executable_bit ~executable )
126+ (file_with_executable_bit ~executable: stats.executable )
127127 path
128128 |> Result. map_error ~f: (fun x -> Path_digest_error. Unix_error x)
129129 | S_DIR when allow_dirs ->
@@ -150,7 +150,8 @@ let path_with_stats ~allow_dirs path (stats : Stats_for_digest.t) =
150150 |> List. sort ~compare: (fun (x , _ ) (y , _ ) -> String. compare x y)
151151 with
152152 | exception E e -> Error e
153- | contents -> Ok (generic (directory_digest_version, contents, stats.st_perm))))
153+ | contents ->
154+ Ok (generic (directory_digest_version, contents, stats.executable))))
154155 | S_DIR | S_BLK | S_CHR | S_FIFO | S_SOCK -> Error Unexpected_kind
155156 in
156157 match stats.st_kind with
0 commit comments