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