fix: publish new Windows outputs without requiring hard links

This commit is contained in:
2026-11-05 12:15:12 +08:00
parent 36f0d7856e
commit 17e55cb7bd
2 changed files with 19 additions and 5 deletions
+6 -2
View File
@@ -14,7 +14,9 @@ _UNCHECKED = object()
def fingerprint(path: Path):
try:
with path.open('rb') as stream:
return hashlib.file_digest(stream, 'sha256').hexdigest()
digest = hashlib.sha256()
for block in iter(lambda: stream.read(1024 * 1024), b''): digest.update(block)
return digest.hexdigest()
except FileNotFoundError:
return None
@@ -42,7 +44,9 @@ def _checked_replace(temporary: Path, path: Path, expected: str | None) -> None:
raise OSError(f'文件发生变化,已停止替换:{path}')
if expected is None:
# Creating the directory entry must fail if another process got there first.
os.link(temporary, path)
# Windows rename is exclusive and also works on volumes without hardlinks.
if os.name == 'nt': os.rename(temporary, path)
else: os.link(temporary, path)
return
backup = _recovery_path(path)
try: