rsync icon indicating copy to clipboard operation
rsync copied to clipboard

`rsync -a` does not always preserve directory modification times

Open jy-lefort opened this issue 3 months ago • 0 comments

Given the enormous amount of open bugs it looks like rsync is unmaintained and I'm losing my time, but still.

Run the following script:

#!/bin/bash

set -euo pipefail

# /tmp is on a tmpfs but the problem also occurs with btrfs
testDir="/tmp/rsyncbug"

sourceDir="$testDir/src"
destDir="$testDir/dest"

rm -rf "$testDir"

mkdir "$testDir"
mkdir "$sourceDir"
mkdir "$sourceDir/foo"

# if this is uncommented, the problem does not occur
#sleep 3

rsync -a "$sourceDir/" "$destDir"

fooSourceMtime=`stat -c %y "$sourceDir/foo"`
fooDestMtime=`stat -c %y "$destDir/foo"`

if [ "$fooSourceMtime" != "$fooDestMtime" ]; then
    echo "ERROR: foo source mtime ($fooSourceMtime) != foo dest mtime ($fooDestMtime)" >&2
    exit 1
fi

Most of the time, the output goes like:

$ ./rsyncbug 
ERROR: foo source mtime (2025-09-02 15:55:20.641734101 +0200) != foo dest mtime (2025-09-02 15:55:20.651733922 +0200)

When sleep 3 is uncommented in the script, the bug does not occur.

jy-lefort avatar Sep 02 '25 13:09 jy-lefort