diff options
author | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-11-21 17:43:00 +0100 |
---|---|---|
committer | AThousandShips <96648715+AThousandShips@users.noreply.github.com> | 2024-11-21 19:30:27 +0100 |
commit | 31c8aadc47170abce59226cf5b4ca547a7636f7b (patch) | |
tree | f884e38d56294443b7cbbca0a2ed349e92ac0f46 | |
parent | 9e6098432aac35bae42c9089a29ba2a80320d823 (diff) | |
download | redot-engine-31c8aadc47170abce59226cf5b4ca547a7636f7b.tar.gz |
[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.
-rw-r--r-- | methods.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/methods.py b/methods.py index 1c33b00051..da6b3419cd 100644 --- a/methods.py +++ b/methods.py @@ -863,16 +863,21 @@ def clean_cache(cache_path: str, cache_limit: int, verbose: bool): texts = [] stats = [] for file in files: - # Failing a utf-8 decode is the easiest way to determine if a file is binary. try: - with open(file, encoding="utf-8") as out: - out.read(1024) - except UnicodeDecodeError: - stats.append((file, *os.stat(file)[6:8])) + # Save file stats to rewrite after modifying. + tmp_stat = os.stat(file) + # Failing a utf-8 decode is the easiest way to determine if a file is binary. + try: + with open(file, encoding="utf-8") as out: + out.read(1024) + except UnicodeDecodeError: + stats.append((file, *tmp_stat[6:8])) + # Restore file stats after reading. + os.utime(file, (tmp_stat[7], tmp_stat[8])) + else: + texts.append(file) except OSError: print_error(f'Failed to access cache file "{file}"; skipping.') - else: - texts.append(file) if texts: count = len(texts) |