aboutsummaryrefslogtreecommitdiff
path: root/src/cpt-lib.in
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2021-08-10 23:19:10 +0000
committermerakor <cem@ckyln.com>2021-08-10 23:19:10 +0000
commit65d72951782ae4c5143b3fbe1bf9a9c7238f775f (patch)
tree691e29bf12f22e63bf12942199225a468848d702 /src/cpt-lib.in
parent779de00952b8cf03a3a34efe9c5ca0f287576546 (diff)
downloadcpt-65d72951782ae4c5143b3fbe1bf9a9c7238f775f.tar.gz
compress: add new function
FossilOrigin-Name: 5f62704fdc9a04856c8ef5f764e8c2da6fd87082c94a673365ecf1cc728c1071
Diffstat (limited to 'src/cpt-lib.in')
-rw-r--r--src/cpt-lib.in25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/cpt-lib.in b/src/cpt-lib.in
index abf5bdf..58c9a0f 100644
--- a/src/cpt-lib.in
+++ b/src/cpt-lib.in
@@ -570,6 +570,18 @@ run_hook() {
CPT_HOOK=$oldCPT_HOOK
}
+# An optional argument could be provided to enforce a compression algorithm.
+# shellcheck disable=2120
+compress() {
+ case ${1:-$CPT_COMPRESS} in
+ bz2) bzip2 -z ;;
+ gz) gzip -6 ;;
+ xz) xz -zT 0 ;;
+ zst) zstd -3 ;;
+ lz) lzip -6 ;;
+ esac
+}
+
decompress() {
case $1 in
*.tar|*.cpio) cat ;;
@@ -1055,19 +1067,8 @@ pkg_tar() {
# Create a tarball from the contents of the built package.
cd "$pkg_dir/$1"
- pax -w . |
- case $CPT_COMPRESS in
- bz2) bzip2 -z ;;
- xz) xz -zT 0 ;;
- gz) gzip -6 ;;
- zst) zstd -3 ;;
- lz) lzip -6 ;;
- *) gzip -6 ;; # Fallback to gzip
- esac \
- > "$bin_dir/$1#$version-$release.tar.$CPT_COMPRESS"
-
+ pax -w . | compress > "$bin_dir/$1#$version-$release.tar.$CPT_COMPRESS"
log "$1" "Successfully created tarball"
-
run_hook post-package "$1" "$bin_dir/$1#$version-$release.tar.$CPT_COMPRESS"
}