Debian Codegraph @

testsuite/atimes_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/atimes.test.
3 #
4 # Test that rsync preserves source atimes when the binary was built with
5 # atimes support. We pin the source file's atime to a known historical
6 # value then sync with -U; the listing (with --atimes in tls) must match
7 # between source and destination.
8
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 '"atimes": true' not in vv.stdout:
17 test_skipped("Rsync is configured without atimes support")
18
19 FROMDIR.mkdir(parents=True, exist_ok=True)
20 foo = FROMDIR / 'foo'
21 foo.touch()
22
23 # `touch -a -t 200102031717.42` -> set atime to 2001-02-03 17:17:42, mtime unchanged.
24 import datetime
25 atime = datetime.datetime(2001, 2, 3, 17, 17, 42).timestamp()
26 mtime = foo.stat().st_mtime
27 os.utime(foo, (atime, mtime))
28
29 # Make the listing include atimes so checkit's tls compare picks up the
30 # transferred atime.
31 rsyncfns.TLS_ARGS = '--atimes'
32
33 checkit(['-rtUgvvv', f'{FROMDIR}/', f'{TODIR}/'], FROMDIR, TODIR)