Unverified Commit a2f1ef69 authored by Marc Cornellà's avatar Marc Cornellà
Browse files

fix(extract): correctly extract rpm files on other directories

parent 0b506fea
...@@ -20,6 +20,7 @@ extract() { ...@@ -20,6 +20,7 @@ extract() {
shift shift
fi fi
local pwd="$PWD"
while (( $# > 0 )); do while (( $# > 0 )); do
if [[ ! -f "$1" ]]; then if [[ ! -f "$1" ]]; then
echo "extract: '$1' is not a valid file" >&2 echo "extract: '$1' is not a valid file" >&2
...@@ -29,6 +30,7 @@ extract() { ...@@ -29,6 +30,7 @@ extract() {
success=0 success=0
extract_dir="${1:t:r}" extract_dir="${1:t:r}"
local full_path="${1:A}"
case "${1:l}" in case "${1:l}" in
(*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$1" | tar xv } || tar zxvf "$1" ;; (*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$1" | tar xv } || tar zxvf "$1" ;;
(*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;; (*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;;
...@@ -57,17 +59,16 @@ extract() { ...@@ -57,17 +59,16 @@ extract() {
(*.z) uncompress "$1" ;; (*.z) uncompress "$1" ;;
(*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$1" -d "$extract_dir" ;; (*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$1" -d "$extract_dir" ;;
(*.rar) unrar x -ad "$1" ;; (*.rar) unrar x -ad "$1" ;;
(*.rpm) mkdir "$extract_dir" && cd "$extract_dir" && rpm2cpio "../$1" | cpio --quiet -id && cd .. ;; (*.rpm)
command mkdir -p "$extract_dir" && builtin cd -q "$extract_dir" \
&& rpm2cpio "$full_path" | cpio --quiet -id ;;
(*.7z) 7za x "$1" ;; (*.7z) 7za x "$1" ;;
(*.deb) (*.deb)
local pwd="$PWD" file="${1:A}" command mkdir -p "$extract_dir/control" "$extract_dir/data"
mkdir -p "$extract_dir/control" "$extract_dir/data" builtin cd -q "$extract_dir"; ar vx "$full_path" > /dev/null
builtin cd -q "$extract_dir"; ar vx "$file" > /dev/null
builtin cd -q control; extract ../control.tar.* builtin cd -q control; extract ../control.tar.*
builtin cd -q ../data; extract ../data.tar.* builtin cd -q ../data; extract ../data.tar.*
builtin cd -q ..; command rm *.tar.* debian-binary builtin cd -q ..; command rm *.tar.* debian-binary ;;
builtin cd -q "$pwd"
;;
(*.zst) unzstd "$1" ;; (*.zst) unzstd "$1" ;;
(*.cab) cabextract -d "$extract_dir" "$1" ;; (*.cab) cabextract -d "$extract_dir" "$1" ;;
(*.cpio) cpio -idmvF "$1" ;; (*.cpio) cpio -idmvF "$1" ;;
...@@ -77,8 +78,11 @@ extract() { ...@@ -77,8 +78,11 @@ extract() {
;; ;;
esac esac
(( success = $success > 0 ? $success : $? )) (( success = success > 0 ? success : $? ))
(( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1" (( success == 0 && remove_archive == 0 )) && rm "$full_path"
shift shift
# Go back to original working directory in case we ran cd previously
builtin cd -q "$pwd"
done done
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment