summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominique Martinet <asmadeus@codewreck.org>2017-12-02 10:53:49 +0100
committerDominique Martinet <asmadeus@codewreck.org>2017-12-02 10:53:49 +0100
commitac8bafef0d120e5092cfd2e4742640b572b864df (patch)
tree5cdecdeeb60632550770426667fd30269cd12296
parentfa3dfcbb53438e3a106821f37c8f884f92676537 (diff)
add main() function, find src only once
-rwxr-xr-xmcp.sh23
1 files changed, 15 insertions, 8 deletions
diff --git a/mcp.sh b/mcp.sh
index 507587d..7653a23 100755
--- a/mcp.sh
+++ b/mcp.sh
@@ -37,14 +37,21 @@ fixstamp-dirs() {
}
export -f fixstamp-dirs
+main() {
+ set -euo pipefail
-set -euo pipefail
+ umask 0077
+ mkdir -p /tmp/dest
+ exec {DESTFD}</tmp/dest
-umask 0077
-mkdir -p /tmp/dest
-exec {DESTFD}</tmp/dest
+ local FINDSRC=$(mktemp /tmp/mcp-find-src.XXXXXXX)
+ trap "rm -f $FINDSRC" EXIT
-cd /tmp/tree
-find . -type d -print0 | xargs -0 bash -c 'mk-dirs "$@"' -- /proc/$$/fd/$DESTFD
-find . -type d -print0 | xargs -0 -P 8 -n 10 bash -c 'cp-dir "$@"' -- /proc/$$/fd/$DESTFD
-find . -type d -print0 | xargs -0 -P 8 -n 10 bash -c 'fixstamp-dirs "$@"' -- /proc/$$/fd/$DESTFD
+ cd /tmp/tree
+ find . -type d -print0 > $FINDSRC
+ xargs -0 bash -c 'mk-dirs "$@"' -- /proc/$$/fd/$DESTFD < $FINDSRC
+ xargs -0 -P 8 -n 10 bash -c 'cp-dir "$@"' -- /proc/$$/fd/$DESTFD < $FINDSRC
+ xargs -0 -P 8 -n 10 bash -c 'fixstamp-dirs "$@"' -- /proc/$$/fd/$DESTFD < $FINDSRC
+}
+
+main