Add some status and safety checks
This commit is contained in:
@@ -17,7 +17,13 @@ cleanup_temp() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Count total files
|
||||
TOTAL_FILES=$#
|
||||
CURRENT_FILE=0
|
||||
|
||||
for INFILE in "$@"; do
|
||||
CURRENT_FILE=$((CURRENT_FILE + 1))
|
||||
echo "Processing file $CURRENT_FILE of $TOTAL_FILES: $INFILE"
|
||||
# Absolute path to old file
|
||||
#OLDFILE=$(realpath "${INFILE}")
|
||||
OUTFILE="${INFILE%.zip}-compress.zip"
|
||||
@@ -70,6 +76,14 @@ for INFILE in "$@"; do
|
||||
|
||||
# Preserve file modification time
|
||||
touch -r "$INFILE" "$OUTFILE"
|
||||
|
||||
# Check that OUTFILE exists and is not empty before deleting INFILE
|
||||
if [ ! -s "$OUTFILE" ]; then
|
||||
echo "Error: Output file is empty or does not exist. Keeping original file."
|
||||
cleanup_temp
|
||||
continue
|
||||
fi
|
||||
|
||||
rm "$INFILE"
|
||||
mv "$OUTFILE" "$INFILE"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user