From 505b17640c5b1acd6515c0daf4a24cd4e955d9a3 Mon Sep 17 00:00:00 2001 From: Stephen Gran Date: Mon, 20 Oct 2008 21:56:27 +0100 Subject: Reuse some code, and change to case statement Signed-off-by: Stephen Gran --- bin/ftpsync | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'bin/ftpsync') diff --git a/bin/ftpsync b/bin/ftpsync index bcca3d9..b5a174a 100755 --- a/bin/ftpsync +++ b/bin/ftpsync @@ -111,6 +111,24 @@ cleanup() { rm -f "${LOCK}"; } +check_rsync() { + + ret=$1 + msg=$2 + + # 24 - vanished source files. Ignored, that should be the target of $UPDATEREQUIRED + # and us re-running. If it's not, uplink is broken anyways. + + case "$1" in + 0) return 0;; + 24) return 0;; + *) + error "ERROR: $msg" + return 1 + ;; + esac +} + ######################################################################## ######################################################################## @@ -335,12 +353,7 @@ while [ -e "${UPDATEREQUIRED}" ]; do result=0 fi # Sync stage 1? - # 24 - vanished source files. Ignored, that should be the target of $UPDATEREQUIRED - # and us re-running. If it's not, uplink is broken anyways. - if [ $result -ne 0 ] && [ $result -ne 24 ]; then - error "ERROR: Sync step 1 went wrong, got errorcode ${result}. Logfile: ${LOG}. Aborting" - exit 3 - fi + check_rsync $result "Sync step 1 went wrong, got errorcode ${result}. Logfile: ${LOG}" || exit 3 HOOK=( HOOKNR=2 @@ -364,10 +377,7 @@ while [ -e "${UPDATEREQUIRED}" ]; do result=0 fi # Sync stage 2? - if [ $result -ne 0 ] && [ $result -ne 24 ]; then - error "ERROR: Sync step 2 went wrong, got errorcode ${result}. Logfile: ${LOG}" - exit 4 - fi + check_rsync $result "Sync step 2 went wrong, got errorcode ${result}. Logfile: ${LOG}" || exit 4 HOOK=( HOOKNR=3 -- cgit v1.2.3