Getting EEXIST out of make_bak_dir()

Jamie Lokier jamie at
Mon Apr 19 06:45:02 MDT 2010

Jordan Russell wrote:
> (followup to thread from last month)
> On 3/9/2010 10:09 AM, Wayne Davison wrote:
> > On Mon, Mar 08, 2010 at 10:02:26AM -0600, Mike Bombich wrote:
> >> rsync: make_bak_dir mkdir "/Volumes/Backup/_Archive_2010_March_07_22-27-43/Users/jsmith/Library/Mail/Mailboxes/   Orchestra" failed: File exists
> > 
> > Is something else creating that directory at the same time?  A race
> > where 2 processes are creating the same directory would be pretty rare,
> > though, so it makes me think that OS X is really failing with the wrong
> > error for a filename it doesn't like.  I note that the next element has
> > an asterisk in it -- should that work OK on that filesystem?
> I reported what appears to be the same issue in 2008:
> and I'm still seeing it today on 3.0.7.
> In my case, nothing else ever accesses the backup directory while rsync
> is running.
> I looked through the sources a while back and noticed that both
> receiver.c and generator.c can invoke make_backup(), either directly or
> via finish_transfer().
> Could it be, then, that this error is caused by rsync's receiver and
> generator processes trying to initially create the backup directory at
> the same time?
> - receiver enters make_backup()
> - generator enters make_backup()
> - receiver checks if dir exists: No
> - generator checks if dir exists: No
> - receiver tries to create dir: Success
> - generator tries to create dir: EEXIST
> I don't remember seeing anything in the code that would prevent the
> generator from deleting a file while the receiver is updating a file.
> Both of those operations, of course, involve moving files into the
> backup directory.

The general rule with this sort of thing is:

    - Check if dir exists.  If yes, return success.
    - Call mkdir.  If ok, return success.
    - If mkdir returned EEXIST, check if the dir exists again.
    - If the dir exists now, return success.
    - Otherwise return the error.

This is why Autoconf checks for a parallel-safe "mkdir -p".  Some
versions of "mkdir -p" do the above sequence, and some don't so it has
to be coded explicitly in script.

-- Jamie

More information about the rsync mailing list