mergerfs/tests/TEST_posix_statfs

61 lines
1.7 KiB
Text
Raw Normal View History

2026-03-21 12:53:54 -05:00
#!/usr/bin/env python3
import os
import sys
import tempfile
from posix_parity import cleanup_dir
2026-03-21 12:53:54 -05:00
from posix_parity import compare_calls
from posix_parity import fail
from posix_parity import join
from posix_parity import mergerfs_mount
from posix_parity import temp_dir
2026-03-21 12:53:54 -05:00
def statvfs_cmp(lhs, rhs):
return (
lhs.f_namemax == rhs.f_namemax
and lhs.f_bsize == rhs.f_bsize
and lhs.f_frsize == rhs.f_frsize
2026-03-21 12:53:54 -05:00
and lhs.f_bsize > 0
and lhs.f_frsize > 0
)
def main():
try:
with mergerfs_mount() as (mount, _):
with tempfile.TemporaryDirectory() as native:
merge_base = temp_dir(mount)
try:
native_base = join(native, os.path.basename(merge_base))
os.makedirs(native_base, exist_ok=True)
err = compare_calls(
"statvfs mount parity",
lambda: os.statvfs(mount),
lambda: os.statvfs(native),
statvfs_cmp,
)
if err:
return fail(err)
err = compare_calls(
"statvfs ENOENT",
lambda: os.statvfs(join(merge_base, "missing")),
lambda: os.statvfs(join(native_base, "missing")),
)
if err:
return fail(err)
return 0
finally:
cleanup_dir(merge_base)
except RuntimeError as exc:
print(str(exc), end="")
return 77
2026-03-21 12:53:54 -05:00
if __name__ == "__main__":
raise SystemExit(main())