diff --git a/src/analysis/index_format.ml b/src/analysis/index_format.ml index 092b0de70..c4a19e814 100644 --- a/src/analysis/index_format.ml +++ b/src/analysis/index_format.ml @@ -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; diff --git a/src/analysis/index_format.mli b/src/analysis/index_format.mli index 4f18a3660..4d68269c7 100644 --- a/src/analysis/index_format.mli +++ b/src/analysis/index_format.mli @@ -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; diff --git a/src/analysis/occurrences.ml b/src/analysis/occurrences.ml index 100f535a2..58d022cf5 100644 --- a/src/analysis/occurrences.ml +++ b/src/analysis/occurrences.ml @@ -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;