Skip to content

Commit 0cfb9a6

Browse files
committed
Merge branch 'cherry-pick-52b5aeaf' into '26.1'
Change Trust_Cache parameter of the Hash APIs to Force_Cache which forces the recompuation of file checksums See merge request eng/toolchain/gnatcoll-core!226
2 parents bec5550 + 74b2211 commit 0cfb9a6

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

core/src/gnatcoll-file_indexes.adb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ package body GNATCOLL.File_Indexes is
4040
Attrs : Stat.File_Attributes;
4141
State : out Entry_State;
4242
Digest : out File_Index_Digest;
43-
Trust_Cache : Boolean := False);
43+
Force_Cache : Boolean := False);
4444

4545
-----------------
4646
-- Clear_Cache --
@@ -59,7 +59,7 @@ package body GNATCOLL.File_Indexes is
5959
function Hash
6060
(Self : in out File_Index;
6161
Path : UTF8.UTF_8_String;
62-
Trust_Cache : Boolean := False)
62+
Force_Cache : Boolean := False)
6363
return File_Index_Digest
6464
is
6565
State : Entry_State;
@@ -70,7 +70,7 @@ package body GNATCOLL.File_Indexes is
7070
Path => Path,
7171
State => State,
7272
Digest => Digest,
73-
Trust_Cache => Trust_Cache);
73+
Force_Cache => Force_Cache);
7474
return Digest;
7575
end Hash;
7676

@@ -79,7 +79,7 @@ package body GNATCOLL.File_Indexes is
7979
Path : UTF8.UTF_8_String;
8080
State : out Entry_State;
8181
Digest : out File_Index_Digest;
82-
Trust_Cache : Boolean := False)
82+
Force_Cache : Boolean := False)
8383
is
8484
Normalized_Path : constant String := GNAT.OS_Lib.Normalize_Pathname
8585
(Path, Resolve_Links => False);
@@ -90,7 +90,7 @@ package body GNATCOLL.File_Indexes is
9090
Stat.Stat (Normalized_Path),
9191
State,
9292
Digest,
93-
Trust_Cache);
93+
Force_Cache);
9494
end Hash;
9595

9696
procedure Hash
@@ -99,7 +99,7 @@ package body GNATCOLL.File_Indexes is
9999
Attrs : Stat.File_Attributes;
100100
State : out Entry_State;
101101
Digest : out File_Index_Digest;
102-
Trust_Cache : Boolean := False)
102+
Force_Cache : Boolean := False)
103103
is
104104
begin
105105
Internal_Hash
@@ -108,7 +108,7 @@ package body GNATCOLL.File_Indexes is
108108
Attrs,
109109
State,
110110
Digest,
111-
Trust_Cache);
111+
Force_Cache);
112112
end Hash;
113113

114114
-------------------
@@ -121,7 +121,7 @@ package body GNATCOLL.File_Indexes is
121121
Attrs : Stat.File_Attributes;
122122
State : out Entry_State;
123123
Digest : out File_Index_Digest;
124-
Trust_Cache : Boolean := False)
124+
Force_Cache : Boolean := False)
125125
is
126126
use File_Maps;
127127
use type Stat.File_Attributes;
@@ -138,7 +138,15 @@ package body GNATCOLL.File_Indexes is
138138
if Prev_Cursor /= No_Element then
139139
Prev := Element (Prev_Cursor);
140140

141-
if Prev.Trust_Hash and then Attrs = Prev.Attrs then
141+
-- If Force_Cache is set, we want to ensure the recomputation of the
142+
-- checksum. This allows to force the update of the cache even though
143+
-- the previous checksum was tagged as trusted. The file could have
144+
-- been modified without Stat picking up the change if the file
145+
-- systems do not have the sufficient time resolution.
146+
if not Force_Cache
147+
and then Prev.Trust_Hash
148+
and then Attrs = Prev.Attrs
149+
then
142150
State := UNCHANGED_FILE;
143151
Digest := Prev.Hash_Digest;
144152

@@ -196,7 +204,7 @@ package body GNATCOLL.File_Indexes is
196204
-- the File_Index DB. In those cases don't trust the hash (i.e: always
197205
-- recompute it in the next query), unless the caller explicitly specify
198206
-- that the value is to be trusted.
199-
Trust_New_Hash := Trust_Cache
207+
Trust_New_Hash := Force_Cache
200208
or else (Ada.Calendar.Clock - Stat.Modification_Time (Attrs)) > 1.0;
201209

202210
-- Add the new entry

core/src/gnatcoll-file_indexes.ads

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ package GNATCOLL.File_Indexes is
6666
Attrs : Stat.File_Attributes;
6767
State : out Entry_State;
6868
Digest : out File_Index_Digest;
69-
Trust_Cache : Boolean := False)
69+
Force_Cache : Boolean := False)
7070
with Inline => True;
7171
-- Get the hash digest for the file located at Path and with file
7272
-- attributes Attrs (obtained with a call to GNATCOLL.OS.Stat). See
@@ -75,27 +75,27 @@ package GNATCOLL.File_Indexes is
7575
-- iterating on a directory using GNATCOLL.OS.Dir. Indeed the Dir_Entry
7676
-- already contains the stat information for the given and thus this avoid
7777
-- calling stat a second time (specially efficient on Windows platform).
78-
-- If Trust_Cache is not set, then checksums savec in the index are
79-
-- considered not trustworthy until 1 second elapsed since its modification
80-
-- time, to prevent potential race conditions. Set it to true to mark it
81-
-- trustworthy.
78+
-- If Force_Cache is set, then we force the recomputation of the checksum
79+
-- and we consider it trustworthy.
80+
-- If Force_Cache is not set, then we rely on the trust we have in the
81+
-- file index checksum up until 1 second elapsed since its modification
82+
-- time, to prevent potential race conditions.
8283

8384
procedure Hash
8485
(Self : in out File_Index;
8586
Path : UTF8.UTF_8_String;
8687
State : out Entry_State;
8788
Digest : out File_Index_Digest;
88-
Trust_Cache : Boolean := False);
89+
Force_Cache : Boolean := False);
8990
-- Same as previous function except that a call to Stat is done
9091
-- automatically to get file attributes.
9192

9293
function Hash
9394
(Self : in out File_Index;
9495
Path : UTF8.UTF_8_String;
95-
Trust_Cache : Boolean := False)
96+
Force_Cache : Boolean := False)
9697
return File_Index_Digest;
9798
-- Same as previous function without State as output.
98-
-- If Trust
9999

100100
procedure Save_Index (Self : File_Index; Filename : UTF8.UTF_8_String);
101101
-- Dump File_Index Self in file Filename

0 commit comments

Comments
 (0)