bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Race condition with cp -r


From: David Phillips
Subject: Race condition with cp -r
Date: Thu, 3 Aug 2006 16:44:53 -0500

A recursive copy will fail if another process creates one of the
destination directories between the stat(2) call and the the mkdir(2)
call.  The relevant code is in copy.c, copy_internal():

     if (new_dst || !S_ISDIR (dst_sb.st_mode))
       {
         /* Create the new directory writable and searchable, so
            we can create new entries in it.  */

         if (mkdir (dst_name, (src_mode & x->umask_kill) | S_IRWXU) != 0)
           {
             error (0, errno, _("cannot create directory %s"),
                    quote (dst_name));
             goto un_backup;
           }

While this implemention appears to follow the letter of the POSIX
specification, it does not seem to follow the intent and at any rate
causes problems for the end user.

I believe that the correct behavior on EEXIST is to start the function over.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]