From 49601bdd9118b961960c22e8c7229375c371b296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20P=C5=82ocharz?= Date: Mon, 27 Jan 2025 17:20:47 +0100 Subject: [PATCH] Fix --open-noatime option not working on files atime of source files could sometimes be overwritten even though --open-noatime option was used. To fix that, optional O_NOATIME flag was added to do_open_nofollow which is also used to open regular files since fix: "fixed symlink race condition in sender" Previously optional O_NOATIME flag was only in do_open. --- syscall.c | 5 +++++ testsuite/open-noatime.test | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 testsuite/open-noatime.test diff --git a/syscall.c b/syscall.c index 34a9bba08..2287e16e0 100644 --- a/syscall.c +++ b/syscall.c @@ -683,6 +683,11 @@ int do_open_nofollow(const char *pathname, int flags) #endif } +#ifdef O_NOATIME + if (open_noatime) + flags |= O_NOATIME; +#endif + #ifdef O_NOFOLLOW fd = open(pathname, flags|O_NOFOLLOW); #else diff --git a/testsuite/open-noatime.test b/testsuite/open-noatime.test new file mode 100644 index 000000000..9cc4b22dd --- /dev/null +++ b/testsuite/open-noatime.test @@ -0,0 +1,26 @@ +#!/bin/sh + +# Test rsync --open-noatime option keeps source atimes intact + +. "$suitedir/rsync.fns" + +$RSYNC -VV | grep '"atimes": true' >/dev/null || test_skipped "Rsync is configured without atimes support" + +mkdir "$fromdir" + +# --open-noatime did not work properly on files with size > 0 +echo content > "$fromdir/foo" +touch -a -t 200102031717.42 "$fromdir/foo" + +TLS_ARGS=--atimes + +"$TOOLDIR/tls" $TLS_ARGS "$fromdir/foo" > "$tmpdir/atime-from-before" + +# Do not use checkit because it uses "diff" which breaks atimes +$RSYNC --open-noatime --archive --recursive --times --atimes -vvv "$fromdir/" "$todir/" + +"$TOOLDIR/tls" $TLS_ARGS "$fromdir/foo" > "$tmpdir/atime-from-after" +diff "$tmpdir/atime-from-before" "$tmpdir/atime-from-after" + +# The script would have aborted on error, so getting here means we've won. +exit 0