diff options
| author | Jayanth Othayoth <ojayanth@in.ibm.com> | 2017-08-09 06:57:12 -0500 |
|---|---|---|
| committer | Patrick Williams <patrick@stwcx.xyz> | 2017-08-22 20:48:18 +0000 |
| commit | c2ece2d7e5516df5dcac5ca263e1b1cfa9b90b35 (patch) | |
| tree | 5c4a3626538dd724ee1072b6418ce1387412833e /tools | |
| parent | e20d5e038eb56c9cf2cc81a6f2844b850bd70adf (diff) | |
| download | phosphor-debug-collector-c2ece2d7e5516df5dcac5ca263e1b1cfa9b90b35.tar.gz phosphor-debug-collector-c2ece2d7e5516df5dcac5ca263e1b1cfa9b90b35.zip | |
dreport: Implementation of file size check function
Change-Id: Ief1b2ebea76f556ba00b2567f8f2db627155d9fd
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/dreport | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tools/dreport b/tools/dreport index 21eba10..65ad282 100755 --- a/tools/dreport +++ b/tools/dreport @@ -63,6 +63,54 @@ declare -x name_dir="" declare -x optional_file="" declare -x dreport_log="" declare -x summary_log="" +declare -x cur_dump_size=0 + +# @brief Calculate file or directory compressed size based on input +# and check whether the size in the the allowed size limit. +# Remove the file or directory from the name_dir +# if the check fails. +# @param $1 Source file or directory +# @return 0 on success, error code if size exceeds the limit. +# Limitation: compress and tar will have few bytes size difference +# between tar and compression approch. +function check_size() +{ + source=$1 + + #No size check required incase dump_size is set to unlimited + if [ $dump_size = $UNLIMITED ]; then + return 0 + fi + + #get the file or directory size + if [[ -d $source ]] && [[ -n $source ]]; then + tar -cf "$source.tar" -C \ + $(dirname "$source") $(basename "$source") + size=$(stat -c%s "$source.tar") + rm "$source.tar" + else + size=$(stat -c%s "$source") + fi + + if [ $((size + cur_dump_size)) -gt $dump_size ]; then + #Exceed the allowed limit, + #tar and compress the files and check the size + tar -Jcf "$name_dir.tar.xz" -C \ + $(dirname "$name_dir") $(basename "$name_dir") + size=$(stat -c%s "$name_dir.tar.xz") + if [ $size -gt $dump_size ]; then + #Remove the the specific data from the name_dir and contniue + rm "$source" "$name_dir.tar.xz" + return $RESOURCE_UNAVAILABLE + else + rm "$name_dir.tar.xz" + fi + fi + + #Remove the compressed file from the name directory + cur_dump_size=$((size + cur_dump_size)) + return $SUCCESS +} # @brief Initial version of the summary log init_summary() |

