mergerfs/tests/TEST_use_fstat_after_unlink

53 lines
1.4 KiB
Text
Raw Normal View History

2019-03-21 21:31:27 -04:00
#!/usr/bin/env python3
import tempfile
2019-03-21 21:31:27 -04:00
import os
import sys
from posix_parity import mergerfs_mount
2019-03-21 21:31:27 -04:00
def main():
try:
with mergerfs_mount() as (mount, _):
(fd, filepath) = tempfile.mkstemp(dir=mount)
2019-03-21 21:31:27 -04:00
x_before = os.lstat(filepath)
x = os.fstat(fd)
2019-03-21 21:31:27 -04: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
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
os.unlink(filepath)
y = os.fstat(fd)
if y.st_nlink != 0:
os.close(fd)
print("fstat after unlink: expected nlink=0, got {}".format(y.st_nlink), end='')
return 1
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
os.close(fd)
return 0
except RuntimeError as exc:
print(str(exc), end="")
return 77
if __name__ == "__main__":
raise SystemExit(main())