From: Steven Baltakatei Sandoval Date: Thu, 2 Jul 2020 19:12:31 +0000 (+0000) Subject: feat(bkgpslog):Include exit codes in checkMakeTar X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02.git/commitdiff_plain/2fc10824a04e0d2153705f9e9d5be33654a99493?hp=f6fb18bdcca1beac6062afe1151cefbe7553961f feat(bkgpslog):Include exit codes in checkMakeTar The change is necessary to decide if VERSION file must be added in case output tar is deleted between writes. --- diff --git a/exec/bkgpslog b/exec/bkgpslog index c66a0e5..187e246 100755 --- a/exec/bkgpslog +++ b/exec/bkgpslog @@ -615,27 +615,41 @@ setScriptTTL() { checkMakeTar() { # Desc: Checks that a valid tar archive exists, creates one otherwise # Usage: checkMakeTar [ path ] + # Version: 1.0.1 # Input: arg1: path of tar archive - # Output: exit code 0 (even if tar had to be created) + # Output: exit code 0 : tar readable + # exit code 1 : tar missing; created + # exit code 2 : tar not readable; moved; replaced # Depends: try, tar, date - local PATH_TAR="$1" + local PATH_TAR returnFlag0 returnFlag1 returnFlag2 + PATH_TAR="$1" # Check if file is a valid tar archive if tar --list --file="$PATH_TAR" 1>/dev/null 2>&1; then ## T1: return success - return 0; + returnFlag0="tar valid"; else ## F1: Check if file exists if [[ -f "$PATH_TAR" ]]; then ### T: Rename file - try mv "$PATH_TAR" "$PATH_TAR""--broken--""$(date +%Y%m%dT%H%M%S)"; + try mv "$PATH_TAR" "$PATH_TAR""--broken--""$(date +%Y%m%dT%H%M%S)" && \ + returnFlag1="tar moved"; else ### F: - : fi ## F2: Create tar archive, return 0 - try tar --create --file="$PATH_TAR" --files-from=/dev/null; + try tar --create --file="$PATH_TAR" --files-from=/dev/null && \ + returnFlag2="tar created"; + fi + + # Determine function return code + if [[ "$returnFlag0" = "tar valid" ]]; then return 0; + elif [[ "$returnFlag2" = "tar created" ]] && ! [[ "$returnFlag1" = "tar moved" ]]; then + return 1; # tar missing so created + elif [[ "$returnFlag2" = "tar created" ]] && [[ "$returnFlag1" = "tar moved" ]]; then + return 2; # tar not readable so moved; replaced fi } # checks if arg1 is tar; creates one otherwise appendArgTar(){ diff --git a/exec/bkgpslog-plan.org b/exec/bkgpslog-plan.org index c494758..519456b 100644 --- a/exec/bkgpslog-plan.org +++ b/exec/bkgpslog-plan.org @@ -26,6 +26,7 @@ when a new session is started. 2020-07-02T18:33Z; bktei> Simplify how the output tar file's existence is checked and its status as a valid tar file is validated. This was done using a new function ~checkMakeTar~. +** TODO Add VERSION if output tar deleted between writes * bkgpslog narrative ** Initialize environment *** Init variables