Rsync, subversion and directories

Wayne Davison wayned at
Sun Nov 13 16:25:06 GMT 2005

On Fri, Nov 11, 2005 at 04:20:09PM +1100, Andrew Crouch wrote:
> Reading the short description of "--force", it appears this flag
> should do the trick - further investigation reveals this is not quite
> so.

The --force option doesn't do anything extra if --delete was already
specified (--force would allow a file to replace a directory without
the --delete option).  When you tell rsync to protect some files,
rsync will not remove the containing directory that holds the protected

> Furthermore, the output of the "-v" flag doesn't imply that the
> directory can be deleted, except when doing a dry run:

Yes, because --dry-run is not smart enough to know that the directory's
deletion is being prevented by the preservation of some excluded

> I was wondering, short of moving the subversion server to the source
> machine, or running rsync twice and doing some output matching, how
> this might be accomplished?

You could always run a simple perl script on the resulting dirs and let
it remove any directory that only contains a .svn dir (which would allow
you to run an svn delete command at that time).  For instance, this
script finds these empty dirs and runs "rm -rf" on them:

use strict;

my %dirs;

open(IN, 'find /dest/path/foo |') or die $!;
while (<IN>) {
    next if m#/.svn/#;
    my($path, $name) = m#^(.*)/([^/]+)$#;
    if ($name eq '.svn') {
	$dirs{$path} += 0;
    } else {
    print "$path = $dirs{$path}\n";

foreach (reverse sort keys %dirs) {
    if ($dirs{$_} == 0) {
	system "rm -rf '$_'";
	# Handle a nested sequence of dirs going empty.
	my($path) = m#^(.*)/#;


More information about the rsync mailing list