Debian Codegraph @

testsuite/omit-times_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 """Coverage of -O (--omit-dir-times) and -J (--omit-link-times) at depth.
3
4 -O preserves file mtimes but leaves directory mtimes alone; -J does the same
5 for symlinks. Verify the distinction deep in the tree: the preserved entries
6 match the source, the omitted ones do not.
7 """
8
9 import os
10
11 from rsyncfns import (
12 FROMDIR, TODIR,
13 assert_mtime_close, make_tree, rmtree, run_rsync, test_fail,
14 walk_dirs, walk_files,
15 )
16
17 src = FROMDIR
18 OLD = 1_400_000_000
19
20
21 def seed():
22 rmtree(src)
23 rmtree(TODIR)
24 make_tree(src, depth=3)
25 for p in list(walk_files(src)) + list(walk_dirs(src)):
26 os.utime(p, (OLD, OLD))
27
28
29 # --- -O: file mtimes preserved, directory mtimes omitted --------------------
30 seed()
31 run_rsync('-rlt', '-O', f'{src}/', f'{TODIR}/')
32 for f in walk_files(src):
33 assert_mtime_close(TODIR / f.relative_to(src), OLD, label=f'-O file {f.name}')
34 # Every directory mtime must be omitted (left at ~now), not just one of them:
35 # the old "at least one differs" check would miss a bug that preserved some.
36 for d in walk_dirs(src):
37 rel = d.relative_to(src)
38 if abs(os.stat(TODIR / rel).st_mtime - OLD) <= 1:
39 test_fail(f"-O preserved the mtime of directory {rel} instead of "
40 "omitting it")
41
42 # --- -J: symlink mtime omitted (where the platform records symlink mtimes) --
43 seed()
44 deep = os.path.join('d1', 'd2', 'd3')
45 os.symlink('f3', src / deep / 'sl')
46 try:
47 os.utime(src / deep / 'sl', (OLD, OLD), follow_symlinks=False)
48 except (NotImplementedError, OSError):
49 print("omit-times: -J check skipped (no symlink-mtime support here)")
50 else:
51 run_rsync('-rlt', '-J', f'{src}/', f'{TODIR}/')
52 dst = TODIR / deep / 'sl'
53 if not os.path.islink(dst):
54 test_fail("-J test: symlink was not copied")
55 if abs(os.lstat(dst).st_mtime - OLD) <= 1:
56 test_fail("-J did not omit the symlink mtime")
57
58 print("omit-times: -O omits dir times, -J omits link times (at depth)")