GNU bug report logs - #13352
cp: ignore EEXIST errors from mkdir

Previous Next

Package: coreutils;

Reported by: Mike Frysinger <vapier <at> gentoo.org>

Date: Fri, 4 Jan 2013 00:06:01 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 13352 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#13352; Package coreutils. (Fri, 04 Jan 2013 00:06:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Mike Frysinger <vapier <at> gentoo.org>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Fri, 04 Jan 2013 00:06:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Mike Frysinger <vapier <at> gentoo.org>
To: bug-coreutils <at> gnu.org
Subject: [PATCH] cp: ignore EEXIST errors from mkdir
Date: Thu,  3 Jan 2013 19:06:36 -0500
If you're copying multiple source trees into a single destination in
parallel (which have overlapping dirs, but not files), you can easily
hit a race condition.

This can crop up more generally if you're running multiple installs
from different build directories in parallel.  You don't get as much
of a speed up due to the parallel I/O, but you do from processing all
the build scripts.

Simple test to reproduce:
	mkdir -p in/`printf %s/ {a..z} {0..10}`
	(rm -rf out; for ((i=0;i<100;++i)); do cp -pPR in out & :; done)

* src/cp.c (make_dir_parents_private): Ignore EEXIST from mkdir.
---
 src/cp.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/cp.c b/src/cp.c
index 625ea0b..b9dff18 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -473,9 +473,15 @@ make_dir_parents_private (char const *const_dir, size_t src_offset,
               mkdir_mode = src_mode & CHMOD_MODE_BITS & ~omitted_permissions;
               if (mkdir (dir, mkdir_mode) != 0)
                 {
-                  error (0, errno, _("cannot make directory %s"),
-                         quote (dir));
-                  return false;
+                  /* If someone else created it between our stat/mkdir,
+                     don't complain.  It's debatable whether we should
+                     also preserve the mode bits in this scenario.  */
+                  if (errno != EEXIST)
+                    {
+                      error (0, errno, _("cannot make directory %s"),
+                             quote (dir));
+                      return false;
+                    }
                 }
               else
                 {
-- 
1.8.0.2





Information forwarded to bug-coreutils <at> gnu.org:
bug#13352; Package coreutils. (Fri, 04 Jan 2013 00:18:02 GMT) Full text and rfc822 format available.

Message #8 received at 13352 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Mike Frysinger <vapier <at> gentoo.org>
Cc: 13352 <at> debbugs.gnu.org
Subject: Re: bug#13352: [PATCH] cp: ignore EEXIST errors from mkdir
Date: Thu, 03 Jan 2013 16:17:03 -0800
Thanks for the bug report, but I'm not sure that's the right
fix.  Wouldn't it be better to address the following FIXME in cp.c?

   /* FIXME: Synch this function with the one in ../lib/mkdir-p.c.  */

The function in mkdir-p.c doesn't have the bug.




Information forwarded to bug-coreutils <at> gnu.org:
bug#13352; Package coreutils. (Fri, 04 Jan 2013 05:15:02 GMT) Full text and rfc822 format available.

Message #11 received at 13352 <at> debbugs.gnu.org (full text, mbox):

From: Mike Frysinger <vapier <at> gentoo.org>
To: bug-coreutils <at> gnu.org
Cc: 13352 <at> debbugs.gnu.org, Paul Eggert <eggert <at> cs.ucla.edu>
Subject: Re: bug#13352: [PATCH] cp: ignore EEXIST errors from mkdir
Date: Fri, 4 Jan 2013 00:16:39 -0500
[Message part 1 (text/plain, inline)]
On Thursday 03 January 2013 19:17:03 Paul Eggert wrote:
> Thanks for the bug report, but I'm not sure that's the right
> fix.  Wouldn't it be better to address the following FIXME in cp.c?
> 
>    /* FIXME: Synch this function with the one in ../lib/mkdir-p.c.  */
> 
> The function in mkdir-p.c doesn't have the bug.

i thought it might, but i didn't want to get into the nuances here.  `mkdir -
p` isn't copying a tree and its set of perms like `cp -pR` does.  it might not 
actually affect the code, but i'm not familiar enough with the code base to 
say.
-mike
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#13352; Package coreutils. (Fri, 04 Jan 2013 05:15:02 GMT) Full text and rfc822 format available.

Changed bug title to 'cp: ignore EEXIST errors from mkdir' from '[PATCH] cp: ignore EEXIST errors from mkdir' Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 30 Oct 2018 04:26:02 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 151 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.