2019-03-21 21:31:27 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
2026-05-07 20:43:42 -05:00
|
|
|
import tempfile
|
2019-03-21 21:31:27 -04:00
|
|
|
import os
|
|
|
|
|
import sys
|
2026-05-07 20:43:42 -05:00
|
|
|
|
|
|
|
|
from posix_parity import mergerfs_mount
|
2019-03-21 21:31:27 -04:00
|
|
|
|
|
|
|
|
|
2026-04-29 17:44:22 -05:00
|
|
|
def main():
|
2026-05-07 20:43:42 -05:00
|
|
|
try:
|
|
|
|
|
with mergerfs_mount() as (mount, _):
|
|
|
|
|
(fd, filepath) = tempfile.mkstemp(dir=mount)
|
2019-03-21 21:31:27 -04:00
|
|
|
|
2026-05-07 20:43:42 -05:00
|
|
|
x_before = os.lstat(filepath)
|
|
|
|
|
x = os.fstat(fd)
|
2019-03-21 21:31:27 -04:00
|
|
|
|
2026-05-07 20:43:42 -05:00
|
|
|
if x.st_size != x_before.st_size:
|
|
|
|
|
os.close(fd)
|
|
|
|
|
os.unlink(filepath)
|
|
|
|
|
print("fstat before unlink: size mismatch lstat={} fstat={}".format(x_before.st_size, x.st_size), end='')
|
|
|
|
|
return 1
|
2019-03-21 21:31:27 -04:00
|
|
|
|
2026-05-07 20:43:42 -05:00
|
|
|
if x.st_mode != x_before.st_mode:
|
|
|
|
|
os.close(fd)
|
|
|
|
|
os.unlink(filepath)
|
|
|
|
|
print("fstat before unlink: mode mismatch lstat={} fstat={}".format(x_before.st_mode, x.st_mode), end='')
|
|
|
|
|
return 1
|
2026-04-29 17:44:22 -05:00
|
|
|
|
2026-05-07 20:43:42 -05:00
|
|
|
os.unlink(filepath)
|
2026-04-29 17:44:22 -05:00
|
|
|
|
2026-05-07 20:43:42 -05:00
|
|
|
y = os.fstat(fd)
|
2026-04-29 17:44:22 -05:00
|
|
|
|
2026-05-07 20:43:42 -05:00
|
|
|
if y.st_nlink != 0:
|
|
|
|
|
os.close(fd)
|
|
|
|
|
print("fstat after unlink: expected nlink=0, got {}".format(y.st_nlink), end='')
|
|
|
|
|
return 1
|
2026-04-29 17:44:22 -05:00
|
|
|
|
2026-05-07 20:43:42 -05:00
|
|
|
if y.st_size != x.st_size:
|
|
|
|
|
os.close(fd)
|
|
|
|
|
print("fstat after unlink: size changed from {} to {}".format(x.st_size, y.st_size), end='')
|
|
|
|
|
return 1
|
2026-04-29 17:44:22 -05:00
|
|
|
|
2026-05-07 20:43:42 -05:00
|
|
|
os.close(fd)
|
|
|
|
|
return 0
|
|
|
|
|
except RuntimeError as exc:
|
|
|
|
|
print(str(exc), end="")
|
|
|
|
|
return 77
|
2026-04-29 17:44:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2026-05-07 20:43:42 -05:00
|
|
|
raise SystemExit(main())
|