Skip to content

Commit c2e6929

Browse files
committed
Fix --open-noatime option not working on files
atime of source files could sometimes be overwritten even though --open-noatime option was used.
1 parent 23d9ead commit c2e6929

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

syscall.c

+5
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,11 @@ int do_open_nofollow(const char *pathname, int flags)
683683
#endif
684684
}
685685

686+
#ifdef O_NOATIME
687+
if (open_noatime)
688+
flags |= O_NOATIME;
689+
#endif
690+
686691
#ifdef O_NOFOLLOW
687692
fd = open(pathname, flags|O_NOFOLLOW);
688693
#else

testsuite/open-noatime.test

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
# Test rsync --open-noatime option keeps source atimes intact
4+
5+
. "$suitedir/rsync.fns"
6+
7+
$RSYNC -VV | grep '"atimes": true' >/dev/null || test_skipped "Rsync is configured without atimes support"
8+
9+
mkdir "$fromdir"
10+
11+
# --open-noatime did not work properly on files with size > 0
12+
echo content > "$fromdir/foo"
13+
touch -a -t 200102031717.42 "$fromdir/foo"
14+
15+
TLS_ARGS=--atimes
16+
17+
"$TOOLDIR/tls" $TLS_ARGS "$fromdir/foo" > "$tmpdir/atime-from-before"
18+
19+
# Do not use checkit because it uses "diff" which breaks atimes
20+
$RSYNC --open-noatime --archive --recursive --times --atimes -vvv "$fromdir/" "$todir/"
21+
22+
"$TOOLDIR/tls" $TLS_ARGS "$fromdir/foo" > "$tmpdir/atime-from-after"
23+
diff "$tmpdir/atime-from-before" "$tmpdir/atime-from-after"
24+
25+
# The script would have aborted on error, so getting here means we've won.
26+
exit 0

0 commit comments

Comments
 (0)