mergerfs/tests/TEST_use_fchown_after_unlink

48 lines
1.2 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)
uid = os.getuid()
gid = os.getgid()
2019-03-21 21:31:27 -04:00
os.fchown(fd, uid, gid)
2019-03-21 21:31:27 -04:00
st1 = os.fstat(fd)
if st1.st_uid != uid or st1.st_gid != gid:
os.close(fd)
os.unlink(filepath)
print("fchown before unlink: expected uid={} gid={}, got uid={} gid={}".format(
uid, gid, st1.st_uid, st1.st_gid), end='')
return 1
2019-03-21 21:31:27 -04:00
os.unlink(filepath)
os.fchown(fd, uid, gid)
st2 = os.fstat(fd)
if st2.st_uid != uid or st2.st_gid != gid:
os.close(fd)
print("fchown after unlink: expected uid={} gid={}, got uid={} gid={}".format(
uid, gid, st2.st_uid, st2.st_gid), end='')
return 1
os.close(fd)
return 0
except RuntimeError as exc:
print(str(exc), end="")
return 77
if __name__ == "__main__":
raise SystemExit(main())