Prevent clang-format from zeroing files

This commit is contained in:
Kovid Goyal 2026-08-11 16:57:43 +05:30
parent 36872d91bb
commit f5fba5e584
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -99,9 +99,12 @@ def run_clang_format(file_path: str) -> tuple[bool, str, str]:
result = subprocess.run(cmd, capture_output=True, input=src)
if result.returncode != 0:
return False, file_path, result.stderr.decode()
new_hash = data_hash(result.stdout)
with open(file_path, 'wb') as f:
f.write(result.stdout)
if result.stdout:
new_hash = data_hash(result.stdout)
with open(file_path, 'wb') as f:
f.write(result.stdout)
else:
new_hash = current_hash
with cache_lock:
cache[rel_path] = new_hash