mergerfs/tests/TEST_use_fallocate_after_unlink

43 lines
1 KiB
Text
Raw Normal View History

2025-06-05 23:47:42 -05:00
#!/usr/bin/env python3
import tempfile
2025-06-05 23:47:42 -05:00
import os
import sys
from posix_parity import mergerfs_mount
2025-06-05 23:47:42 -05:00
def main():
try:
with mergerfs_mount() as (mount, _):
(fd, filepath) = tempfile.mkstemp(dir=mount)
2025-06-05 23:47:42 -05:00
os.posix_fallocate(fd, 0, 1024)
2025-06-05 23:47:42 -05:00
st1 = os.fstat(fd)
if st1.st_size < 1024:
os.close(fd)
os.unlink(filepath)
print("fallocate before unlink: expected size >= 1024, got {}".format(st1.st_size), end='')
return 1
2025-06-05 23:47:42 -05:00
os.unlink(filepath)
os.posix_fallocate(fd, 1024, 2048)
st2 = os.fstat(fd)
if st2.st_size < 1024 + 2048:
os.close(fd)
print("fallocate after unlink: expected size >= 3072, got {}".format(st2.st_size), end='')
return 1
os.close(fd)
return 0
except RuntimeError as exc:
print(str(exc), end="")
return 77
if __name__ == "__main__":
raise SystemExit(main())