* about #55
authormitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Thu, 4 Oct 2012 09:05:56 +0000 (09:05 +0000)
committermitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Thu, 4 Oct 2012 09:05:56 +0000 (09:05 +0000)
 * find -> sort -> uniq -> xargs -> cmp
 * don't check existence of path
 * don't check path is regular file or directory

git-svn-id: https://lab.mitty.jp/svn/lab/trunk@170 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

TipAndDoc/.bin/cmpdir [new file with mode: 0755]

diff --git a/TipAndDoc/.bin/cmpdir b/TipAndDoc/.bin/cmpdir
new file mode 100755 (executable)
index 0000000..f8f546a
--- /dev/null
@@ -0,0 +1,35 @@
+#! /bin/sh
+
+if [ $# -lt 2 ]; then
+    echo "Usage: $0 directory1 directory2"
+    exit 1
+fi
+if [ -d "$1" -a -d "$2" ]; then
+    echo "$0: start comparing '$1' and '$2'" >&2
+fi
+
+list=`mktemp --tmpdir cmpdir.list.XXXXXXXXXX` || exit 1
+tmp=`mktemp --tmpdir cmpdir.tmp.XXXXXXXXXX` || exit 1
+trap "rm -- '$list' '$tmp'" EXIT
+
+wc=$PWD
+cd "$1"
+find ./ -print0 >> "$tmp"
+cd $wc
+
+cd "$2"
+find ./ -print0 >> "$tmp"
+cd $wc
+
+sort -z "$tmp" | uniq -z > "$list"
+
+comppath () {
+    [ ! -e "$1/$3" ] && [ ! -e "$2/$3" ] &&
+        (echo "$0: something wrong abount '$3'" >&2; return)
+    [ -e "$1/$3" ] && [ ! -e "$2/$3" ] &&
+        (echo "Only in '$1': '$3'" >&2; return)
+    [ ! -e "$1/$3" ] && [ -e "$2/$3" ] &&
+        (echo "Only in '$2': '$3'" >&2; return)
+}
+
+xargs -a "$list" -0 -n 1 -I entry cmp "$1/entry" "$2/entry"