#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
# All Rights Reserved
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
USAGE="usage: dircmp [-d] [-s] [-wn] dir1 dir2"
TEMPDIR=`mktemp -d /var/tmp/dir.XXXXXX`
if [ -z "$TEMPDIR" ]; then exit 1; fi
typeset -i exitstat=0
typeset -i sizediff
typeset -i cmpdiff
typeset -i Sflag=0
typeset -i Dflag=0
typeset -i fsize1
typeset -i fsize2
typeset -l LFBOUND=2147483648
width=72
#
# function to generate consistent "diff" output whether or not files are intact
#
*text) ;;
*script) ;;
continue
;;
continue
;;
continue
;;
esac
*text) ;;
*script) ;;
continue
;;
continue
;;
continue
;;
esac
#
# If either is a "large file" use bdiff (LF aware),
# else use diff.
#
then cmd="diff"
else cmd="bdiff"
fi
fi
}
#
# dircmp entry point
#
while getopts dsw: i
do
case $i in
d) Dflag=1;;
s) Sflag=1;;
if [ $? = 2 ]
then echo "dircmp: numeric argument required"
exit 2
fi
;;
\?) echo $USAGE
exit 2;;
esac
done
#
D0=`pwd`
D1=$1
D2=$2
if [ $# -lt 2 ]
then echo $USAGE
exit 1
elif [ ! -d "$D1" ]
exit 2
elif [ ! -d "$D2" ]
exit 2
fi
#
# which are common to both hierarchies as well as unique to each.
# At this point, print those that are unique.
#
cd "$D1"
cd "$D0"
cd "$D2"
-e "/^ /w $TEMPDIR/dc$$c" \
-e "/^ [^ ]/w $TEMPDIR/dc$$d" \
-e "/^[^ ]/w $TEMPDIR/dc$$e"
#
# Use -lgn to avoid problem when user or group names are too long, causing
# expected field separator to be missing
# Avoid other potential problems by piping through sed:
# - Remove: Spaces in size field for block & character special files
# '71, 0' becomes '710'
# - For file name, do not print '-> some_file'
# The following sed is to read filenames with special characters
cd "$D0"
cd "$D1"
cd "$D0"
#
# Process the results of the 'ls -lLgnd' to obtain file size info
# and identify a large file's existence.
#
#
# A window of opportunity exists where the ls -lLgnd above
# could produce different
# results if any of the files were removed since the find command.
# If the pair of reads above results in different values (file names) for 'a'
# and 'b', then get the file pointers in sync before continuing, and display
# "different" message as customary.
#
if [[ "$a" != "$b" ]]; then
while [[ "$a" < "$b" ]]; do
then echo "different $a"
fi
done
while [[ "$a" > "$b" ]]; do
then echo "different $b"
fi
done
fi
cmpdiff=0
sizediff=0
if [ -d "$D1"/"$a" ]
then echo "directory $a"
fi
elif [ -f "$D1"/"$a" ]
then
#
# If the file sizes are different, then we can skip the run
# of "cmp" which is only used to determine 'same' or 'different'.
# If the file sizes are the same, we still need to run "cmp"
#
then
sizediff=1
else
cmpdiff=$?
fi
then echo "same $a"
fi
else echo "different $a"
then
fi
fi
then echo "special $a"
fi
fi
exit $exitstat