use pv for large files

This commit is contained in:
Ville Rantanen
2021-11-29 14:43:13 +02:00
parent 17f281a501
commit b0765eccd3

View File

@@ -27,6 +27,7 @@ for ((i=1; i<=${#@}; i++)) {
if [[ ${#paths[@]} -eq 0 ]]; then if [[ ${#paths[@]} -eq 0 ]]; then
paths+=(".") paths+=(".")
fi fi
which pv &>/dev/null && PVBIN=$( which pv )
set -e set -e
echo "Updating: $list_name" echo "Updating: $list_name"
test -f "$list_name" || touch "$list_name" test -f "$list_name" || touch "$list_name"
@@ -45,10 +46,17 @@ _update() {
fi fi
if test -f "$1"; then if test -f "$1"; then
if awk '{ print substr($0,35) }' "$list_name" | grep -qFx "$1"; then if awk '{ print substr($0,35) }' "$list_name" | grep -qFx "$1"; then
echo "$1: exist" echo "Exists: $1"
else else
echo "$1: new" echo "New: $1"
md5sum "$1" >> "$list_name" size=$( stat -c %s "$1" )
if [[ $size -gt 100000000 ]] && [[ -n "$PVBIN" ]]; then
# Use pv is size > 100MB
sum=$( $PVBIN "$1" | md5sum | awk '{ print $1 }' )
printf "%s %s\n" "$sum" "$1" >> "$list_name"
else
md5sum "$1" >> "$list_name"
fi
updates_done=1 updates_done=1
fi fi
fi fi