revert factorisation attempt

This commit is contained in:
fatalerrors
2026-03-25 14:37:20 +01:00
parent 043fbaef0b
commit 0c51363d86

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org> # Copyright (c) 2013-2026 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details. # Protected by the BSD3 license. Please read bellow for details.
# #
# * Redistribution and use in source and binary forms, # * Redistribution and use in source and binary forms,
@@ -381,56 +381,11 @@ export -f utaz
# -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest] # -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]
taz() taz()
{ {
_taz_compress_generic()
{
local preferred="$1" fallback="$2" thread_arg="$3" threads="$4" level="$5" verbose="$6" file="$7" message="$8"
local cmd='' procopt=()
if [[ -n "$message" ]]; then
disp W "$message"
fi
if command -v -- "$preferred" >/dev/null 2>&1; then
cmd="$preferred"
elif [[ -n "$fallback" ]] && command -v -- "$fallback" >/dev/null 2>&1; then
cmd="$fallback"
if [[ $threads -gt 1 ]]; then
disp W "${fallback} doesn't support multithreading, falling back to 1 thread."
disp W "Consider installing ${preferred} for multithreading abilities."
threads=1
fi
else
disp E "Program '${preferred}' or '${fallback}' are not installed, aborting."
return 127
fi
# build command line options
if [[ -n "$thread_arg" ]] && [[ $threads -gt 0 ]]; then
procopt+=("$thread_arg" "$threads")
fi
if [[ -n "$verbose" ]]; then
procopt+=("$verbose")
fi
# special behaviour for xz and lzop:
if [[ "$cmd" == "xz" ]]; then
"$cmd" "${procopt[@]}" --compress --keep -"$level" "$file"
return $?
fi
if [[ "$cmd" == "lzop" ]] && [[ $threads -gt 1 ]]; then
disp W "lzop doesn't support multithreading, falling back to 1 thread."
threads=1
fi
"$cmd" "${procopt[@]}" --keep -"$level" "$file"
return $?
}
_doxz() _doxz()
{ {
_taz_compress_generic "xz" "" "-T" "$2" "$3" "$4" "$1" "xz format is not suited for long term archiving. See https://www.nongnu.org/lzip/xz_inadequate.html for details." command -v xz >/dev/null 2>&1 || {
disp E "The program 'xz' is not installed, aborting."
return 127
} }
[[ $4 ]] && local verb='-v' [[ $4 ]] && local verb='-v'
@@ -446,22 +401,89 @@ taz()
_dolz() _dolz()
{ {
_taz_compress_generic "plzip" "lzip" "--threads" "$2" "$3" "$4" "$1" "" local procopt="--threads $2"
local command=plzip
command -v plzip >/dev/null 2>&1 || {
command -v lzip >/dev/null 2>&1 || {
disp E "Program 'plzip' or 'lzip' are not installed, aborting."
return 127
}
command=lzip
local procopt=""
[[ $2 -gt 1 ]] &&
disp W "lzip doesn't support multithreading, falling back to 1 thread." &&
disp W "Consider installing plzip to obtain multithreading abilities."
}
[[ $4 ]] && local verb="-vv"
# Compresse au format lzip (lzma)
$command $verb $procopt --keep -$3 $1
return $?
} }
_dogz() _dogz()
{ {
_taz_compress_generic "pigz" "gzip" "--processes" "$2" "$3" "$4" "$1" "" local procopt="--processes $2"
local command=pigz
command -v pigz >/dev/null 2>&1 || {
command -v gzip >/dev/null 2>&1 || {
disp E "Programs 'pigz' or 'gzip' are not installed, aborting."
return 127
}
local command="gzip --compress"
local procopt=""
[[ $2 -gt 1 ]] &&
disp W "gzip doesn't support multithreading, falling back to 1 thread." &&
disp W "Consider installing pigz to obtain multithreading abilities."
}
[[ $4 ]] && local verb="--verbose"
# Compresse au format bz2
$command $verb $procopt --keep -$3 $1
return $?
} }
_dobz2() _dobz2()
{ {
_taz_compress_generic "pbzip2" "bzip2" "-p" "$2" "$3" "$4" "$1" "" local procopt="-p$2"
local command=pbzip2
command -v pbzip2 >/dev/null 2>&1 || {
command -v bzip2 >/dev/null 2>&1 || {
disp E "The program 'pbzip2' or 'bzip2' are not installed, aborting."
return 127
}
local command=bzip2
local procopt=""
[[ $2 -gt 1 ]] &&
disp W "bzip2 doesn't support multithreading, falling back to 1 thread." &&
disp W "Consider installing pbzip2 to obtain multithreading abilities."
}
[[ $4 ]] && local verb="-v"
# Compresse au format bz2
$command $verb --compress $procopt --keep -$3 $1
return $?
} }
_dolzo() _dolzo()
{ {
_taz_compress_generic "lzop" "" "" "$2" "$3" "$4" "$1" "" command -v lzop >/dev/null 2>&1 || {
disp E "The program 'lzop' is not installed, aborting."
return 127
}
[[ $4 ]] && local verb='-v'
[[ $2 -gt 1 ]] && disp W "lzop doesn't support multithreading, falling back to 1 thread."
# Compresse au format lzo
lzop --keep -$3 $1
return $?
} }
local PARSED local PARSED