Skip to content

Instantly share code, notes, and snippets.

@keithel
Last active May 11, 2023 21:13
Show Gist options
  • Save keithel/32630e3da37538ce7adaa01da7154878 to your computer and use it in GitHub Desktop.
Save keithel/32630e3da37538ce7adaa01da7154878 to your computer and use it in GitHub Desktop.
Testing if rsync on macOS will properly synchronize xattrs, ACLs, and hard links
#!/bin/bash
set -e -u
T=$(echo ${TMPDIR}rsync_test*)
if [[ -e $T ]]; then
TMP_DIR=$T #"$TMPDIR/rsync_test*"
cd $TMP_DIR
rm -Rf a b ls_a_out ls_b_out
else
TMP_DIR=$(mktemp -d -t rsync_test)
fi
cd $TMP_DIR
mkdir a
echo "This is a quarantined file" > a/quarantine
xattr -w com.apple.quarantine '0002;Safari;https://example.com/;' a/quarantine
echo "This is a file with an ACL" > a/acl
chmod +a "$USER allow write" a/acl
ln -s quarantine a/symlink
ln a/acl a/hardlink
rsync -r -a -H -E a/ b
ls -le@ a > ls_a_out 2>&1
ls -le@ b > ls_b_out 2>&1
diff ls_a_out ls_b_out
echo "Created rsync test files in $TMP_DIR."
echo "You can see the xattr, acl, symlink and hardlink using:"
echo " ls -le@ $TMP_DIR/a"
echo "$TMP_DIR"
@keithel
Copy link
Author

keithel commented May 11, 2023

macOS Monerey 12.6.3
rsync version 2.6.9 protocol version 29

1,2c1,2
< total 24
< -rw-r--r--+ 2 kyzikadmin  staff  27 May 11 14:11 acl
---
> total 8
> -rw-------+ 1 kyzikadmin  staff   0 May 11 14:11 acl
4,7c4
< -rw-r--r--+ 2 kyzikadmin  staff  27 May 11 14:11 hardlink
<  0: user:kyzikadmin allow write
< -rw-r--r--@ 1 kyzikadmin  staff  27 May 11 14:11 quarantine
<       com.apple.quarantine    33 
---
> -rw-r--r--  1 kyzikadmin  staff  27 May 11 14:11 quarantine

this version of rsync does not preserve hardlinks even with -H which should preserve them, and does not preserve apple extended attributes.
In fact, with -H, it doesn't even try to copy the hard link at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment