From: Antonio Ospite Date: Fri, 29 Jan 2010 12:25:34 +0000 (+0100) Subject: Check functions return values. X-Git-Url: https://git.ao2.it/etcdiff.git/commitdiff_plain/329c34a9649727679faf13416d9aa5836aecd003?ds=inline Check functions return values. --- diff --git a/etcdiff.include b/etcdiff.include index c82468d..f25076b 100644 --- a/etcdiff.include +++ b/etcdiff.include @@ -7,7 +7,7 @@ _get_unpack_package() if [ "x$PACKAGE" = "x" ]; then echo "Argument missing." - exit 1 + return 1 fi FILEPATH=$(apt-cache show $PACKAGE | grep ^Filename | cut -d ' ' -f 2-) @@ -15,7 +15,7 @@ _get_unpack_package() if [ "x$FILEPATH" = "x" ]; then echo "Package '$PACKAGE' does not exist." - exit 1 + return 1 fi ARCHIVE=$(basename $FILEPATH) @@ -33,14 +33,14 @@ _do_etcdiff() if [ "x$ETCBASEDIR" = "x" ]; then echo "Argument missing." - exit 1 + return 1 fi REPORT_NAME=$(basename $ETCBASEDIR) # Report diff between debian conf and our local one rm -f $REPORTDIR/$REPORT_NAME.diff - find $PREFIX/etc -type f | \ + [ -d $PREFIX/etc ] && find $PREFIX/etc -type f | \ while read file; do diff -ruN $ETCBASEDIR/${file#$PREFIX/} ${file#$PREFIX} >> $REPORTDIR/$REPORT_NAME.diff @@ -48,7 +48,7 @@ _do_etcdiff() # Report symlinks in /etc rm -f $REPORTDIR/$REPORT_NAME.symlinks - find $PREFIX/etc -type l | \ + [ -d $PREFIX/etc ] && find $PREFIX/etc -type l | \ while read file; do stat -c '%N' $file >> $REPORTDIR/$REPORT_NAME.symlinks @@ -71,10 +71,19 @@ etcdiff_system() fi echo "Getting package $p..." - _get_unpack_package $p + if ! _get_unpack_package $p; + then + continue + fi # save the original etc dir for later processing - cp -ir $TEMPDIR/$PACKAGE/etc $TEMPDIR/__debian_etc + if [ ! -d $TEMPDIR/$p/etc ]; + then + echo "Warning: package $p does not have any /etc, but 'dpkg -L' shows it" + continue + else + cp -ir $TEMPDIR/$p/etc $TEMPDIR/__debian_etc + fi done _do_etcdiff $TEMPDIR/__debian_etc @@ -89,7 +98,7 @@ etcdiff_by_package() if [ "x$PACKAGE" = "x" ]; then echo "Argument missing." - exit 1 + return 1 fi if dpkg --status $PACKAGE | grep -q 'not-installed'; @@ -105,9 +114,21 @@ etcdiff_by_package() return 1 fi - _get_unpack_package $PACKAGE + if ! _get_unpack_package $PACKAGE; + then + return 1 + fi - _do_etcdiff $TEMPDIR/$PACKAGE $TEMPDIR/$PACKAGE + if [ ! -d $TEMPDIR/$PACKAGE/etc ]; + then + echo "Warning: package $p does not have any /etc, but 'dpkg -L' shows it" + return 1 + fi + + if ! _do_etcdiff $TEMPDIR/$PACKAGE $TEMPDIR/$PACKAGE; + then + return 1 + fi return 0 } @@ -119,7 +140,7 @@ etcdiff_by_file() if [ "x$FILE" = "x" ]; then echo "Argument missing." - exit 1 + return 1 fi if [ ! -e $FILE ]; @@ -149,7 +170,10 @@ etcdiff_by_file() then diff -ruN /dev/null $FILE > $REPORTDIR/$REPORT_NAME.diff else - _get_unpack_package $PACKAGE + if ! _get_unpack_package $PACKAGE; + then + return 1 + fi diff -ruN $FILE $TEMPDIR/$PACKAGE/$FILE > $REPORTDIR/$REPORT_NAME.diff fi