Debian Codegraph @

tests/testlib/advance-fs-time.py

raw
1 import os
2 import sys
3
4
5 def main():
6 if len(sys.argv) != 2:
7 print(f"Usage: {sys.argv[0]} <file>", file=sys.stderr)
8 sys.exit(1)
9
10 path = sys.argv[1]
11
12 try:
13 fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_WRONLY)
14 os.close(fd)
15 created = True
16 except FileExistsError:
17 created = False
18
19 try:
20 t0 = os.stat(path).st_mtime
21 while True:
22 os.utime(path)
23 if os.stat(path).st_mtime != t0:
24 break
25 finally:
26 if created:
27 os.unlink(path)
28
29
30 if __name__ == "__main__":
31 main()