mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-26 07:53:58 +00:00
Fix test_size_on_disk_accurate for large st_blksize, fixes #7250
python's io.BufferedWriter sizes its buffer based on st_blksize.
If the write fits in this buffer, then it's possible the data from
idx.write() has not been flushed through to ,the underlying filesystem,
and getsize(fileno()) sees a too-short (or even empty) file.
Also, getsize is only documented as accepting path-like objects;
passing a fileno seems to work only because the implementation
blindly forwards everything through to os.stat without checking.
Passing unopened_tempfile avoids all three problems
- on windows, it doesn't rely on re-opening NamedTemporaryFile
(the issue which led to cc0ad321dc
)
- we're following the documented API of getsize(path-like)
- the file is closed (thus flushed) inside idx.write, before getsize()
This commit is contained in:
parent
daf890ebfa
commit
079d9256ee
1 changed files with 3 additions and 3 deletions
|
@ -258,9 +258,9 @@ def test_size_on_disk_accurate(self):
|
|||
idx = ChunkIndex()
|
||||
for i in range(1234):
|
||||
idx[H(i)] = i, i**2
|
||||
with tempfile.NamedTemporaryFile() as file:
|
||||
idx.write(file)
|
||||
size = os.path.getsize(file.fileno())
|
||||
with unopened_tempfile() as filepath:
|
||||
idx.write(filepath)
|
||||
size = os.path.getsize(filepath)
|
||||
assert idx.size() == size
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue