orphan dirs and files with --delete

Eric Whiting ewhiting at amis.com
Mon Mar 22 23:49:15 GMT 2004

rsync (2.5.[67]) --delete fails on dirs with the w bit cleared. (example below)
Rsync will sync a dir with w bit clear, but will not remove it with --delete. 

This is not a big problem, but it will create situations where there are
'orphaned' files.

Has anyone else had this problem? 

It looks like a change would be needed in robust_unlink (util.c). This function
would have to do a chmod on dirs that are locked down before it does the unlink.
(syncing as user root doesn't have this problem)

The CHECK_RO macro in syscall.c only checks for file being RO. It doesn't check
for the dir being RO.


here is an example:

cd /tmp

# cleanup 
chmod -R a+w source dest
rm -rf source dest

# create a dir and subdir and chmod
mkdir source
cd source
touch file1 file2
mkdir dir1;touch dir1/file3 dir1/file4
chmod a-w dir1

# rsync to dest
mkdir /tmp/dest
rsync --delete -av /tmp/source/ /tmp/dest

# clean up source a little bit
chmod a+w dir1
rm -rf dir1

# attempt to clean up dest with rsync (this --delete will fail)
rsync --delete -av /tmp/source/ /tmp/dest
cd /tmp

OUTPUT (of final rsync)
/tmp/source> rsync --delete -av /tmp/source/ /tmp/dest
building file list ... done
delete_one: unlink dir1/file4: Permission denied
delete_one: unlink dir1/file3: Permission denied
wrote 102 bytes  read 20 bytes  244.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files could not be transferred (code 23) at main.c(620)

More information about the rsync mailing list