[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[coreutils] cp --parents parallel
From: |
Rob Gom |
Subject: |
[coreutils] cp --parents parallel |
Date: |
Mon, 18 Oct 2010 16:52:13 +0200 |
Hi all,
this is my first post to this list, which I think is the best place to
ask. I have searched web, but couldn't found an answer.
In one of my makefiles I use parallel execution. One of the targets
executed simultaneously tries to copy files to one root directory. And
sometimes it fails.
I have reproduced the problem with the following bash script:
#!/bin/bash
while true; do
directory=`mktemp -d`
(sleep 1s; cp --update --parents a/b/c/xxx.txt $directory) &
(sleep 1s; cp --update --parents a/b/d/xxx.txt $directory) &
(sleep 1s; cp --update --parents a/b/e/xxx.txt $directory) &
(sleep 1s; cp --update --parents a/b/f/xxx.txt $directory) &
sleep 10s
rm -rf $directory
sleep 10s
done
I would expect having at the end:
$directory/a/b/c/xxx.txt
$directory/a/b/d/xxx.txt
$directory/a/b/e/xxx.txt
$directory/a/b/f/xxx.txt
But it failed immediately with:
$ bash ./test.sh
cp: cp: cp: cannot make directory `/tmp/tmp.tbAF9E58QA/a'cannot make
directory `/tmp/tmp.tbAF9E58QA/a'cannot make directory
`/tmp/tmp.tbAF9E58QA/a': File exists
: File exists
: File exists
^C
I assume that all spawned processes found that there's no target
directory and attempted to create it. But when cp first assumed that
there's no directory
and it was created in the meantime, it failed.
Is my script correct? Is cp behaviour correct? How can I avoid the
problem in the future?
I have tried to browse coreutils source, but I'm not good enough to
find the place, however in the comments I saw something like (create
ancestors?) "this function should be safe
even when called from different processes".
I use Ubuntu 10.04 with the following coreutils version: 7.4-2ubuntu3.
Regards,
Robert
- [coreutils] cp --parents parallel,
Rob Gom <=