-
Notifications
You must be signed in to change notification settings - Fork 258
Fix archive extraction to ensure it always extracts to the given path #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,29 +74,39 @@ function download() | |
| function extract() | ||
| { | ||
| local archive="$1" | ||
| local dest="${2:-${archive%/*}}" | ||
| local dest="$2" | ||
| local dest_dir="$(dirname "$2")" | ||
| local tmp="$dest_dir/tmp" | ||
|
|
||
| mkdir -p "$dest" || return $? | ||
| rm -rf "$dest" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably have a trailing |
||
| mkdir -p "$tmp" || return $? | ||
|
|
||
| case "$archive" in | ||
| *.tgz|*.tar.gz) | ||
| run tar -xzf "$archive" -C "$dest" || return $? | ||
| run tar -xzf "$archive" -C "$tmp" || return $? | ||
| ;; | ||
| *.tbz|*.tbz2|*.tar.bz2) | ||
| run tar -xjf "$archive" -C "$dest" || return $? | ||
| run tar -xjf "$archive" -C "$tmp" || return $? | ||
| ;; | ||
| *.txz|*.tar.xz) | ||
| debug "xzcat $archive | tar -xf - -C $dest" | ||
| xzcat "$archive" | tar -xf - -C "$dest" || return $? | ||
| debug "xzcat $archive | tar -xf - -C $tmp" | ||
| xzcat "$archive" | tar -xf - -C "$tmp" || return $? | ||
| ;; | ||
| *.zip) | ||
| run unzip "$archive" -d "$dest" || return $? | ||
| run unzip "$archive" -d "$tmp" || return $? | ||
| ;; | ||
| *) | ||
| error "Unknown archive format: $archive" | ||
| return 1 | ||
| ;; | ||
| esac | ||
|
|
||
| local extracted=("$tmp"/*) | ||
| if (( ${#extracted[@]} != 1 )); then | ||
| error "Multiple extracted directories under $tmp" | ||
| return 1 | ||
| fi | ||
| mv "${extracted[0]}" "$dest" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be a good idea to add an |
||
| } | ||
|
|
||
| # | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dirname "$dest"might be nice?"$2"and"$dest"are same here, so just an optional nit.