2019-03-21 21:31:27 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
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
|
|
|
x_before = os.lstat(filepath)
|
|
|
|
|
x = os.fstat(fd)
|
2019-03-21 21:31:27 -04:00
|
|
|
|
2026-04-29 17:44:22 -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-04-29 17:44:22 -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
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
raise SystemExit(main())
|