add keep-all options
This commit is contained in:
@@ -434,6 +434,7 @@ export -f utaz
|
||||
# -d, --delete Delete source file or directory after success
|
||||
# -f, --format Chose archive format in the given list. If several format are
|
||||
# given, the smalest is kept
|
||||
# -K, --keep-all Keep every produced version instead of only the smallest
|
||||
# -p, --parallel Number of threads to use, or 'auto' to use detected CPU count
|
||||
# -v, --verbose Display progress where possible
|
||||
# -q, --quiet Display less messages (only errors and warnings)
|
||||
@@ -590,7 +591,7 @@ taz()
|
||||
}
|
||||
|
||||
local PARSED
|
||||
PARSED=$(getopt -o hdf:p:vq123456789 --long help,delete,format:,parallel:,verbose,quiet --name "taz" -- "$@")
|
||||
PARSED=$(getopt -o hdf:Kp:vq123456789 --long help,delete,format:,keep-all,parallel:,verbose,quiet --name "taz" -- "$@")
|
||||
# shellcheck disable=SC2181 # getopt return code is checked immediately after
|
||||
if [ $? -ne 0 ]; then
|
||||
disp E "Invalid options, use \"taz --help\" to display usage."
|
||||
@@ -608,6 +609,7 @@ taz()
|
||||
printf "\t-d, --delete\tDelete source file or directory after success\n"
|
||||
printf "\t-f, --format\tChose archive format in the given list. If several format are\n"
|
||||
printf "\t\t\tgiven, the smalest is kept\n"
|
||||
printf "\t-K, --keep-all\tKeep every produced version instead of only the smallest\n"
|
||||
printf "\t-p, --parallel\tNumber of threads, or 'auto' for runtime CPU count\n"
|
||||
printf "\t-v, --verbose\tDisplay progress where possible\n"
|
||||
printf "\t-q, --quiet\tDisplay less messages (only errors and warnings)\n"
|
||||
@@ -640,6 +642,11 @@ taz()
|
||||
shift 2
|
||||
;;
|
||||
|
||||
-K|--keep-all)
|
||||
local keepall=1
|
||||
shift
|
||||
;;
|
||||
|
||||
-p|--parallel)
|
||||
local nproc=$2
|
||||
shift 2
|
||||
@@ -734,10 +741,11 @@ taz()
|
||||
[[ $donetar -gt 0 ]] && fname=$item.tar
|
||||
|
||||
# Compress the archive with every requested format; the smallest
|
||||
# resulting file is kept and the others are discarded.
|
||||
local candidates=() fmt exec_code aborted=0
|
||||
# resulting file is kept and the others are discarded (unless --keep-all).
|
||||
local candidates=() fmt exec_code aborted=0 tar_requested=0
|
||||
for fmt in "${compforms[@]}"; do
|
||||
if [[ $fmt == tar ]]; then
|
||||
tar_requested=1
|
||||
candidates+=("$fname")
|
||||
continue
|
||||
fi
|
||||
@@ -803,15 +811,23 @@ taz()
|
||||
done
|
||||
fi
|
||||
|
||||
# Discard every archive but the smallest, then drop the intermediate
|
||||
# tar unless it is the kept archive.
|
||||
for c in "${candidates[@]}"; do
|
||||
[[ $c != "$winner" ]] && rm -f -- "$c"
|
||||
done
|
||||
[[ $donetar -gt 0 && $fname != "$winner" ]] && rm -f -- "$fname"
|
||||
# Discard every archive but the smallest, unless --keep-all was given.
|
||||
# Either way, drop the intermediate tar when it was not itself a
|
||||
# requested output format.
|
||||
if [[ -z $keepall ]]; then
|
||||
for c in "${candidates[@]}"; do
|
||||
[[ $c != "$winner" ]] && rm -f -- "$c"
|
||||
done
|
||||
fi
|
||||
[[ $donetar -gt 0 && $tar_requested -eq 0 ]] && rm -f -- "$fname"
|
||||
|
||||
[[ ${#compforms[@]} -gt 1 ]] &&
|
||||
disp I "\t Kept smallest archive: ${winner} ($(_taz_human "$winner_size"))."
|
||||
if [[ -n $keepall ]]; then
|
||||
[[ ${#compforms[@]} -gt 1 ]] &&
|
||||
disp I "\t Kept all produced archives (smallest: ${winner}, $(_taz_human "$winner_size"))."
|
||||
else
|
||||
[[ ${#compforms[@]} -gt 1 ]] &&
|
||||
disp I "\t Kept smallest archive: ${winner} ($(_taz_human "$winner_size"))."
|
||||
fi
|
||||
|
||||
if [[ $willrm ]]; then
|
||||
disp I "\t Deleting original source as asked... "
|
||||
|
||||
Reference in New Issue
Block a user