2019-03-21 21:31:27 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import os
|
2026-04-29 17:44:22 -05:00
|
|
|
import stat
|
2019-03-21 21:31:27 -04:00
|
|
|
import sys
|
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
|
|
|
2026-04-29 17:44:22 -05:00
|
|
|
def main():
|
|
|
|
|
(fd, filepath) = tempfile.mkstemp(dir=sys.argv[1])
|
2019-03-21 21:31:27 -04:00
|
|
|
|
2026-04-29 17:44:22 -05:00
|
|
|
os.fchmod(fd, 0o700)
|
2019-03-21 21:31:27 -04:00
|
|
|
|
2026-04-29 17:44:22 -05:00
|
|
|
st1 = os.fstat(fd)
|
|
|
|
|
if stat.S_IMODE(st1.st_mode) != 0o700:
|
|
|
|
|
os.close(fd)
|
|
|
|
|
os.unlink(filepath)
|
|
|
|
|
print("fchmod before unlink: expected mode 0o700, got 0o{:o}".format(stat.S_IMODE(st1.st_mode)), end='')
|
|
|
|
|
return 1
|
2019-03-21 21:31:27 -04:00
|
|
|
|
2026-04-29 17:44:22 -05:00
|
|
|
os.unlink(filepath)
|
|
|
|
|
|
|
|
|
|
os.fchmod(fd, 0o755)
|
|
|
|
|
|
|
|
|
|
st2 = os.fstat(fd)
|
|
|
|
|
if stat.S_IMODE(st2.st_mode) != 0o755:
|
|
|
|
|
os.close(fd)
|
|
|
|
|
print("fchmod after unlink: expected mode 0o755, got 0o{:o}".format(stat.S_IMODE(st2.st_mode)), end='')
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
os.close(fd)
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
raise SystemExit(main())
|