| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import datetime |
| 9 |
import os |
| 10 |
import platform |
| 11 |
import shlex |
| 12 |
import subprocess |
| 13 |
|
| 14 |
import rsyncfns |
| 15 |
from rsyncfns import FROMDIR, TMPDIR, TODIR, TOOLDIR, run_rsync, test_fail, test_skipped |
| 16 |
|
| 17 |
|
| 18 |
vv = run_rsync('-VV', check=True, capture_output=True) |
| 19 |
if '"atimes": true' not in vv.stdout: |
| 20 |
test_skipped("Rsync is configured without atimes support") |
| 21 |
|
| 22 |
|
| 23 |
if platform.system() != 'Linux': |
| 24 |
test_skipped("O_NOATIME is only supported on Linux") |
| 25 |
|
| 26 |
FROMDIR.mkdir(parents=True, exist_ok=True) |
| 27 |
foo = FROMDIR / 'foo' |
| 28 |
foo.write_text("content\n") |
| 29 |
|
| 30 |
|
| 31 |
atime = datetime.datetime(2001, 2, 3, 17, 17, 42).timestamp() |
| 32 |
mtime = foo.stat().st_mtime |
| 33 |
os.utime(foo, (atime, mtime)) |
| 34 |
|
| 35 |
rsyncfns.TLS_ARGS = '--atimes' |
| 36 |
|
| 37 |
|
| 38 |
def _tls_listing(path: str) -> str: |
| 39 |
cmd = [str(TOOLDIR / 'tls')] + shlex.split(rsyncfns.TLS_ARGS) + [str(path)] |
| 40 |
return subprocess.check_output(cmd, text=True) |
| 41 |
|
| 42 |
|
| 43 |
before = _tls_listing(foo) |
| 44 |
(TMPDIR / 'atime-from-before').write_text(before) |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
run_rsync('--open-noatime', '--archive', '--recursive', '--times', |
| 49 |
'--atimes', '-vvv', f'{FROMDIR}/', f'{TODIR}/') |
| 50 |
|
| 51 |
after = _tls_listing(foo) |
| 52 |
(TMPDIR / 'atime-from-after').write_text(after) |
| 53 |
|
| 54 |
if before != after: |
| 55 |
diff = subprocess.run( |
| 56 |
['diff', '-u', |
| 57 |
str(TMPDIR / 'atime-from-before'), |
| 58 |
str(TMPDIR / 'atime-from-after')], |
| 59 |
capture_output=True, text=True, |
| 60 |
) |
| 61 |
print(diff.stdout) |
| 62 |
test_fail("source atime changed across rsync --open-noatime run") |