fix: claim a partial only under its own name

Opening and locking a partial download are two steps. Between them another run could finish, rename the same file into place and release its lock. The second run then locked the installed BIOS, read its full size as a finished partial and truncated it to download again. After the lock the partial's name must still point at the locked file, or the run downloads into a private copy.
This commit is contained in:
Abdessamad Derraz committed 2026-10-20 00:31:00 +02:00
1 parent d1ff233990
commit aea67e998f
4 files changed
+38 -2

No files matched your search

+11
View File
@@ -2604,6 +2604,17 @@ def _claim_partial(path: Path) -> BinaryIO | None:
except OSError:
handle.close()
return None
# Opened and locked are two steps: in between, the run that held the
# partial may have renamed it into place and released it. The lock then
# sits on the installed BIOS, which looks like a finished partial and
# would be truncated. Only the file still under the partial's name is ours.
try:
ours = os.path.samestat(os.fstat(handle.fileno()), os.lstat(path))
except OSError:
ours = False
if not ours:
handle.close()
return None
return handle