Skip to content

Commit

Permalink
index: rely on size only to check status
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Jan 8, 2024
1 parent 5d74c46 commit f45caa6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/analysis/index_format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let add tbl uid locs =
Hashtbl.replace tbl uid (LidSet.union locs locations)
with Not_found -> Hashtbl.add tbl uid locs

type stat = { mtime : float; size : int }
type stat = { mtime : float; size : int; source_digest: string option }
type index = {
defs : (Shape.Uid.t, LidSet.t) Hashtbl.t;
approximated : (Shape.Uid.t, LidSet.t) Hashtbl.t;
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/index_format.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ val add : ('a, LidSet.t) Hashtbl.t -> 'a -> LidSet.t -> unit

module Stats : Map.S with type key = String.t

type stat = { mtime : float; size : int }
type stat = { mtime : float; size : int; source_digest: string option }
type index = {
defs : (Shape.Uid.t, LidSet.t) Hashtbl.t;
approximated : (Shape.Uid.t, LidSet.t) Hashtbl.t;
Expand Down
7 changes: 4 additions & 3 deletions src/analysis/occurrences.ml
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ let check Index_format.{ stats; _ } file =
let open Index_format in
match Stats.find_opt file stats with
| None -> log ~title:"stat_check" "No mtime found for file %S." file; true
| Some { mtime; size } ->
| Some { size; _ } ->
try
let stats = Unix.stat file in
let equal =
Float.equal stats.st_mtime mtime
|| Int.equal stats.st_size size
(* This is fast but approximative. A better option would be to check
[mtime] and then [source_digest] if the times differ. *)
Int.equal stats.st_size size
in
log ~title:"stat_check"
"File %s has been modified since the index was built." file;
Expand Down

0 comments on commit f45caa6

Please sign in to comment.