Skip to content

Commit 31c8aad

Browse files
[Buildsystem] Prevent cache check mangling access time
Checking for text files using `open` changes `atime`, which breaks cache access sorting, this ensures the cache access time is preserved.
1 parent 9e60984 commit 31c8aad

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

methods.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -863,16 +863,21 @@ def clean_cache(cache_path: str, cache_limit: int, verbose: bool):
863863
texts = []
864864
stats = []
865865
for file in files:
866-
# Failing a utf-8 decode is the easiest way to determine if a file is binary.
867866
try:
868-
with open(file, encoding="utf-8") as out:
869-
out.read(1024)
870-
except UnicodeDecodeError:
871-
stats.append((file, *os.stat(file)[6:8]))
867+
# Save file stats to rewrite after modifying.
868+
tmp_stat = os.stat(file)
869+
# Failing a utf-8 decode is the easiest way to determine if a file is binary.
870+
try:
871+
with open(file, encoding="utf-8") as out:
872+
out.read(1024)
873+
except UnicodeDecodeError:
874+
stats.append((file, *tmp_stat[6:8]))
875+
# Restore file stats after reading.
876+
os.utime(file, (tmp_stat[7], tmp_stat[8]))
877+
else:
878+
texts.append(file)
872879
except OSError:
873880
print_error(f'Failed to access cache file "{file}"; skipping.')
874-
else:
875-
texts.append(file)
876881

877882
if texts:
878883
count = len(texts)

0 commit comments

Comments
 (0)