Use a temp directory for temporary files

This commit is contained in:
Dan Church 2022-10-31 16:00:31 -05:00
parent c7e6ff5a3e
commit 306fb7e8c9
Signed by: h3xx
GPG Key ID: EA2BF379CD2CDBD0
1 changed files with 3 additions and 5 deletions

View File

@ -42,9 +42,9 @@ KEEP_BACKUP_SUFFIX=
FORCE_OVERWRITE=0
ENCODE_THRU_WARNINGS=0
TEMP_FILES=()
TEMP_DIR=$(mktemp -d -t "${0##*/}.XXXXXX")
cleanup() {
rm -f -- "${TEMP_FILES[@]}"
rm -fr -- "$TEMP_DIR"
}
trap 'cleanup' EXIT
@ -222,9 +222,6 @@ use_smaller() {
}
TEMP=$(mktemp -t "${0##*/}.XXXXXX")
TEMP_FILES+=("$TEMP")
QPDF_ARGS=(
--compression-level=9
--deterministic-id
@ -248,6 +245,7 @@ fi
ERRORS=0
FREED_TOTAL=0
for FILE in "${FILES[@]}"; do
TEMP=$(mktemp -p "$TEMP_DIR" -t 'file.XXXXXX')
rm -f -- "$TEMP"
BEGIN_FILESIZE=$(file_size "$FILE")