diff options
| author | Jayanth Othayoth <ojayanth@in.ibm.com> | 2017-08-09 07:26:45 -0500 |
|---|---|---|
| committer | Patrick Williams <patrick@stwcx.xyz> | 2017-08-22 20:48:19 +0000 |
| commit | 8d0446e37fd32d8a38c4eb38e195b004bd740583 (patch) | |
| tree | acd6c25706ea2c34484dd773d94076110cdb217e /tools | |
| parent | acf46e33954e359875ae104428e0b8903a538254 (diff) | |
| download | phosphor-debug-collector-8d0446e37fd32d8a38c4eb38e195b004bd740583.tar.gz phosphor-debug-collector-8d0446e37fd32d8a38c4eb38e195b004bd740583.zip | |
dreport: Added error handling support in packaging function
Change-Id: I8c99fe708f9d5b90a6f868524c7694f520f8f23a
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/dreport | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/tools/dreport b/tools/dreport index 8af95b5..43d2acb 100755 --- a/tools/dreport +++ b/tools/dreport @@ -45,6 +45,7 @@ declare -r SUMMARY_LOG="summary.log" declare -r DREPORT_LOG="dreport.log" declare -r TMP_DIR="/tmp" declare -r EPOCHTIME=$(date +"%s") +declare -r TIME_STAMP="date -u" #Error Codes declare -r SUCCESS="0" @@ -477,36 +478,35 @@ function package() dest_dir=$TMP_DIR fi - #TODO openbmc/openbmc#1506 Enable file level compression. #tar and compress the files. - tar_file="$name_dir.tar.xz" - tar -Jcf "$tar_file" -C "$TMP_DIR" "$name" + tar -Jcf "$name_dir.tar.xz" -C \ + $(dirname "$name_dir") $(basename "$name_dir") + + if [ $? -ne 0 ]; then + echo "Could not create the compressed tar file" + rm -r "$name_dir" + return $INTERNAL_FAILURE + fi #remove the temporary name specific directory rm -r "$name_dir" - #check the file size is in the allowed limit - if [ $(stat -c%s "$tar_file") -gt $dump_size ]; then - echo "File size exceeds the limit allowed" - rm -rf "$TMP_DIR" - exit 1 - #TODO openbmc/openbmc#1506 Revisit the error handling - fi - echo "Report is available in $dump_dir" if [ "$TMP_DIR" == "$dump_dir" ]; then - return + return $SUCCESS fi #copy the compressed tar file into the destination - cp "$tar_file" "$dump_dir" + cp "$name_dir.tar.xz" "$dump_dir" if [ $? -ne 0 ]; then - echo "Failed to copy the $tar_file to $dump_dir" - return - else - rm -rf "$TMP_DIR" + echo "Failed to copy the $name_dir.tar.xz to $dump_dir" + rm "$name_dir.tar.xz" + return $INTERNAL_FAILURE fi + + #Remove the temporary copy of the file + rm "$name_dir.tar.xz" } # @brief log the error message # @param error message @@ -560,7 +560,7 @@ function main() initialize result=$? if [[ ${result} -ne $SUCCESS ]]; then - echo $(date -u)" Error: Failed to initialize, Exiting" + echo $(TIME_STAMP)" Error: Failed to initialize, Exiting" exit; fi @@ -571,6 +571,13 @@ function main() collect_data package #package the dump + result=$? + if [[ ${result} -ne $SUCCESS ]]; then + echo $($TIME_STAMP)" Error: Failed to package, Exiting" + else + echo $($TIME_STAMP)" Sucessfully completed" + exit; + fi } TEMP=`getopt -o n:d:i:t:s:f:vVqh \ |

