Skip to content

Commit

Permalink
filename: check that file exists before stat on written_since
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed May 19, 2022
1 parent c2d6cd9 commit c7a2ae1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/core/opamFilename.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@ let touch t =
let chmod t p =
Unix.chmod (to_string t) p

let written_since file =
let last_update =
(Unix.stat (to_string file)).Unix.st_mtime
in
(Unix.time () -. last_update)

let of_string s =
let dirname = Filename.dirname s in
let basename = Filename.basename s in
Expand Down Expand Up @@ -227,6 +221,14 @@ let opt_file filename =
let with_contents fn filename =
fn (read filename)

let written_since file =
if exists file then
let last_update =
(Unix.stat (to_string file)).Unix.st_mtime
in
(Unix.time () -. last_update)
else -1.

let check_suffix filename s =
Filename.check_suffix (to_string filename) s

Expand Down

0 comments on commit c7a2ae1

Please sign in to comment.