Debian Codegraph @

testsuite/crtimes_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/crtimes.test.
3 #
4 # Test that rsync preserves source create times when the binary was built
5 # with crtimes support. Touch tricks: setting an older time via touch sets
6 # the create time to the mtime; setting a newer time affects only mtime.
7
8 import datetime
9 import os
10
11 import rsyncfns
12 from rsyncfns import FROMDIR, TODIR, checkit, run_rsync, test_skipped
13
14
15 vv = run_rsync('-VV', check=True, capture_output=True)
16 if '"crtimes": true' not in vv.stdout:
17 test_skipped("Rsync is configured without crtimes support")
18
19 FROMDIR.mkdir(parents=True, exist_ok=True)
20 (FROMDIR / 'foo').write_text("hiho\n")
21
22
23 def _utime(path, when: 'datetime.datetime') -> None:
24 ts = when.timestamp()
25 os.utime(path, (ts, ts))
26
27
28 # Touch fromdir to an old time then to a newer time -- in shells with the
29 # right kernel support this leaves the create time pinned to the older.
30 _utime(FROMDIR, datetime.datetime(2001, 1, 1, 11, 11, 11))
31 _utime(FROMDIR, datetime.datetime(2002, 2, 2, 22, 22, 22))
32
33 _utime(FROMDIR / 'foo', datetime.datetime(2001, 11, 11, 11, 11, 11))
34 _utime(FROMDIR / 'foo', datetime.datetime(2002, 12, 12, 22, 22, 22))
35
36 rsyncfns.TLS_ARGS = '--crtimes'
37
38 checkit(['-rtgvvv', '--crtimes', f'{FROMDIR}/', f'{TODIR}/'], FROMDIR, TODIR)