From 22a2ffd7de3771cba4f1ff375b6b072ae41ee5a9 Mon Sep 17 00:00:00 2001 From: mitty Date: Thu, 4 Oct 2012 09:47:28 +0000 Subject: [PATCH] * #55 * recursively exec cmpdir script in cmpdir * cmpdir dir1 dir2 target -> check dir1/target dir2/target and then cmp dir1/target dir2/target * almost finished git-svn-id: https://lab.mitty.jp/svn/lab/trunk@171 7d2118f6-f56c-43e7-95a2-4bb3031d96e7 --- TipAndDoc/.bin/cmpdir | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/TipAndDoc/.bin/cmpdir b/TipAndDoc/.bin/cmpdir index f8f546a..edae02f 100755 --- a/TipAndDoc/.bin/cmpdir +++ b/TipAndDoc/.bin/cmpdir @@ -4,6 +4,23 @@ if [ $# -lt 2 ]; then echo "Usage: $0 directory1 directory2" exit 1 fi +if [ $# -eq 3 ]; then + [ -d "$1/$3" ] && [ -d "$2/$3" ] && + exit + [ ! -e "$1/$3" ] && [ ! -e "$2/$3" ] && + echo "$0: something wrong abount '$3'" >&2 && exit + [ -e "$1/$3" ] && [ ! -e "$2/$3" ] && + echo "Only in '$1': '$3'" >&2 && exit + [ ! -e "$1/$3" ] && [ -e "$2/$3" ] && + echo "Only in '$2': '$3'" >&2 && exit + [ -f "$1/$3" ] && [ -d "$2/$3" ] && + echo "'$1' is a regular file but '$2' is a directory" >&2 && exit + [ -d "$1/$3" ] && [ -f "$2/$3" ] && + echo "'$1' is a directory but '$2' is a regular file" >&2 && exit + + cmp -s "$1/$3" "$2/$3" || echo "$1/$3" "$2/$3" are differ >&2 + exit +fi if [ -d "$1" -a -d "$2" ]; then echo "$0: start comparing '$1' and '$2'" >&2 fi @@ -14,22 +31,14 @@ trap "rm -- '$list' '$tmp'" EXIT wc=$PWD cd "$1" -find ./ -print0 >> "$tmp" +find -print0 >> "$tmp" cd $wc cd "$2" -find ./ -print0 >> "$tmp" +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" +xargs -a "$list" -0 -n 1 -I entry $0 "$1" "$2" "entry" -- 1.7.9.5