diff --git a/.config/bash/module/archive.sh b/.config/bash/module/archive.sh index bd90e16..4bf0456 100644 --- a/.config/bash/module/archive.sh +++ b/.config/bash/module/archive.sh @@ -122,8 +122,8 @@ archive_check() echo -e "${status}" # extract hash from name. - local saved="${target##*-}" - saved="${saved%%.*}" + local data=($(_archive_parse ${target})) + local saved=${data[2]} # calculate actual hash. local actual=$(pv "${target}" | sha1sum | cut -d\ -f1) @@ -164,16 +164,16 @@ archive_prune() # Iterate counter. ((count++)) - - local name="${target%_*}" - local data="${target##*_}" - local time="${data%%-*}" + + local data=($(_archive_parse ${target})) + local name="${data[0]}" + local time="${data[1]}" local copies=($(ls ${name}_*)) # Iterate each copy. for copy in "${copies[@]}"; do - local copy_data="${copy##*_}" - local copy_time="${copy_data%%-*}" + local copy_data=($(_archive_parse ${copy})) + local copy_time="${copy_data[1]}" if [[ "${copy_time}" -lt "${time}" ]]; then echo -e "${name}: prune ${copy_time}." @@ -219,8 +219,8 @@ unarchive() echo -e "${status}" # extract hash from name. - local saved="${target##*-}" - saved="${saved%%.*}" + local data=($(_archive_parse "${target}")) + local saved="${data[2]}" # calculate actual hash. local actual=$(pv "${target}" | sha1sum | cut -d\ -f1) @@ -369,6 +369,21 @@ archive_convert() done } +_archive_parse() +{ + local input="${1}" + local name="${input%_*}" + local format="${input##*.}" + local data="${input##*_}"; data="${data%.*}" + local date="${data%%-*}" + local hash="${data##*-}" + + echo "${name}" + echo "${date}" + echo "${hash}" + echo "${format}" +} + # export everything, primarily for use with parallel.. export -f archive archive_fast archive_check unarchive archive_name _ARCHIVE_DATE export _ARCHIVE_PATTERN