Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e431ac

Browse files
committed
update.py: preserve latest downloaded file if unchanged
1 parent 823832c commit 9e431ac

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

update.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,20 @@ def remove_if_exists(filepath):
144144

145145

146146
def fetch_and_rename(fetchurl: str, target_file: str, new_name: str) -> None:
147+
# Fetch into a temporary filename (new_name) and only replace the
148+
# real target if content actually changed. This avoids touching
149+
# mtimes when the fetched content is identical and prevents
150+
# unnecessary Sphinx rebuilds.
147151
fetch_url(fetchurl, fpath=new_name, verbose=False)
152+
153+
try:
154+
# If target exists and is identical, remove fetched temp and skip replace
155+
if os.path.exists(target_file) and filecmp.cmp(new_name, target_file, shallow=False):
156+
debug(f"No change for {target_file} (fetched content identical)")
157+
os.remove(new_name)
158+
return
159+
except OSError as e:
160+
debug(f"Failed to compare fetched file and target: {e}")
148161
progress(f"Renaming {new_name} to {target_file}")
149162
os.replace(new_name, target_file)
150163

0 commit comments

Comments
 (0)