Walk appdata once for the space check, and refuse to export when it cannot be measured

This commit is contained in:
Gmer4Lfe
2026-08-24 18:46:26 -04:00
parent b58282b3d6
commit 492757ce70
+19 -6
View File
@@ -144,13 +144,26 @@ if [[ ! -d "$OUTPUT_DIR" ]]; then
fi fi
# Space check — conservative: appdata × 1.1 # Space check — conservative: appdata × 1.1
APPDATA_SIZE_KB=$(du -sk "$APPDATA_PATH" 2>/dev/null | cut -f1) #
OUTPUT_FREE_KB=$(df "$OUTPUT_DIR" --output=avail 2>/dev/null | tail -1 | tr -d ' ') # One traversal of the appdata tree, not two. This measured it twice — once with du -sk for the
REQUIRED_KB=$(( APPDATA_SIZE_KB * 11 / 10 )) # arithmetic and again with du -sh for the message — and walked $OUTPUT_DIR twice as well. On a
APPDATA_SIZE_H=$(du -sh "$APPDATA_PATH" 2>/dev/null | cut -f1) # container's appdata that is the expensive call in this script, paid twice to print a string.
OUTPUT_FREE_H=$(df -h "$OUTPUT_DIR" --output=avail 2>/dev/null | tail -1 | tr -d ' ') # An unreadable size is not a small size. Defaulting either of these to 0 makes the check below
# pass — a zero requirement clears any free space, and the export then runs toward a disk that
# was never measured. Unknown stops here instead.
if ! APPDATA_SIZE_MB=$(dir_size_mb "$APPDATA_PATH"); then
error "Could not measure $APPDATA_PATH — refusing to export without a space check"
exit 1
fi
if ! OUTPUT_FREE_MB=$(disk_free_mb "$OUTPUT_DIR"); then
error "Could not read free space on $OUTPUT_DIR — refusing to export without a space check"
exit 1
fi
REQUIRED_MB=$(( APPDATA_SIZE_MB * 11 / 10 ))
APPDATA_SIZE_H=$(format_mb "$APPDATA_SIZE_MB")
OUTPUT_FREE_H=$(format_mb "$OUTPUT_FREE_MB")
if [[ "$OUTPUT_FREE_KB" -lt "$REQUIRED_KB" ]]; then if [[ "$OUTPUT_FREE_MB" -lt "$REQUIRED_MB" ]]; then
error "Insufficient space in $OUTPUT_DIR" error "Insufficient space in $OUTPUT_DIR"
error "Estimated need: ~${APPDATA_SIZE_H} (×1.1 conservative) — available: ${OUTPUT_FREE_H}" error "Estimated need: ~${APPDATA_SIZE_H} (×1.1 conservative) — available: ${OUTPUT_FREE_H}"
exit 1 exit 1