rsync icon indicating copy to clipboard operation
rsync copied to clipboard

hard linking fails into a soft-linked directory

Open ynikitenko opened this issue 2 years ago • 0 comments

I'm developing a wrapper around rsync with a git-like interface. I use hard links for commits and I was going to use soft links for different branches. However, when creating hard links, rsync instead copies data if the path is inside a soft link:

mkdir tmp && cd tmp
touch a
mkdir -p .ys/commits
# this works correctly
rsync -a --link-dest=../../.. --exclude=/.ys . .ys/commits/1
stat -c %h a
# 2 hard links

Now let's create a symbolic link .ys/commits instead of a real directory (as it was before).

cd .ys
mkdir branches
mv commits/ branches/
ln -s branches/commits/ .
cd ..
rsync -a --link-dest=../../.. --exclude=/.ys . .ys/commits/2
stat -c %h a
# still 2 hard links

Interestingly, if commits is a soft link in the same directory, hard links work correctly:

rm .ys/commits
mv .ys/branches/commits/ .ys/other  # other is a normal directory
ln -s other .ys/commits  # commits are a soft link to other
rsync -a --link-dest=../../.. --exclude=/.ys . .ys/commits/3
stat -c %h a
# 3 hard links now, correct

rsync version 3.2.7 protocol version 31 Arch Linux 6.3.5-arch1-1 x86_64 GNU/Linux, ext4 filesystem.

ynikitenko avatar Jun 05 '23 12:06 ynikitenko