GNU bug report logs -
#13352
cp: ignore EEXIST errors from mkdir
Previous Next
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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
This bug report was last modified 6 years and 229 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.