Archive : Check before xz convert.
This commit is contained in:
parent
ca2b5d7408
commit
b5ccc453c9
|
@ -108,15 +108,7 @@ function archive_check() {
|
|||
[[ "${targets}" = "" ]] && targets=($(_ls_archive))
|
||||
|
||||
process() {
|
||||
# extract hash from name.
|
||||
local data=($(_archive_parse ${target}))
|
||||
local saved=${data[2]}
|
||||
|
||||
# calculate actual hash.
|
||||
local actual=$(pv ${target} | sha1sum | cut -d\ -f1)
|
||||
|
||||
# compare hashes.
|
||||
[[ "${actual}" = "${saved}" ]]
|
||||
_archive_check "${target}"
|
||||
}
|
||||
|
||||
_iterate_targets process ${targets[@]}
|
||||
|
@ -180,6 +172,9 @@ function archive_xz() {
|
|||
return 1
|
||||
fi
|
||||
|
||||
# Check integrity.
|
||||
_archive_check "${target}" || return 1
|
||||
|
||||
# Recompress.
|
||||
local hash=$(pv "${target}" | gzip -d | xz -9e | tee "${tmp}" | sha1sum | cut -d\ -f1)
|
||||
|
||||
|
@ -236,27 +231,18 @@ function unarchive() {
|
|||
[[ "${targets}" = "" ]] && targets=$(_ls_archive)
|
||||
|
||||
process() {
|
||||
# extract hash from name.
|
||||
local data=($(_archive_parse ${target}))
|
||||
local saved=${data[2]}
|
||||
|
||||
# calculate actual hash.
|
||||
local actual=$(pv ${target} | sha1sum | cut -d\ -f1)
|
||||
# Validate.
|
||||
_archive_check "${target}" || return 1
|
||||
|
||||
# extract if hash matched or show error if not.
|
||||
if [[ "${saved}" = "${actual}" ]]; then
|
||||
case "${target##*.}" in
|
||||
"txz")
|
||||
pv ${target} | xz -d | tar -xf -
|
||||
;;
|
||||
"tgz")
|
||||
pv ${target} | gzip -d | tar -xf -
|
||||
;;
|
||||
esac
|
||||
else
|
||||
_error "Failed."
|
||||
return 1
|
||||
fi
|
||||
case "${target##*.}" in
|
||||
"txz")
|
||||
pv ${target} | xz -d | tar -xf -
|
||||
;;
|
||||
"tgz")
|
||||
pv ${target} | gzip -d | tar -xf -
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_iterate_targets process ${targets[@]}
|
||||
|
@ -358,6 +344,18 @@ function _filter_archive() {
|
|||
grep -E ${_archive_pattern}
|
||||
}
|
||||
|
||||
function _archive_check() {
|
||||
# extract hash from name.
|
||||
local data=($(_archive_parse ${target}))
|
||||
local saved=${data[2]}
|
||||
|
||||
# calculate actual hash.
|
||||
local actual=$(pv ${target} | sha1sum | cut -d\ -f1)
|
||||
|
||||
# compare hashes.
|
||||
[[ "${actual}" = "${saved}" ]]
|
||||
}
|
||||
|
||||
complete -o filenames -F _comp_archive_grep archive_check unarchive archive_rm
|
||||
complete -o filenames -F _comp_archive_grep_fast archive_xz
|
||||
complete -o filenames -F _comp_archive_name archive_name
|
||||
|
|
Reference in a new issue