Compare commits

..
2 Commits
5 changed files with 42 additions and 20 deletions
+1 -2
View File
@@ -354,8 +354,7 @@ for arr in sonarr radarr lidarr; do
big_unknown=$((big_unknown + 1))
done < <(find "$entry" -type f -size +"${min_mb}"M 2>/dev/null)
size_mb=$(du -sm "$entry" 2>/dev/null | cut -f1)
size_mb=${size_mb:-0}
size_mb=$(dir_size_mb "$entry") || size_mb=0
if [[ "$has_media" == false ]] && (( big_unknown > 0 )); then
warn " no recognised media, but $big_unknown large file(s) of unknown type — holding: $base"
+19 -6
View File
@@ -144,13 +144,26 @@ if [[ ! -d "$OUTPUT_DIR" ]]; then
fi
# 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 ' ')
REQUIRED_KB=$(( APPDATA_SIZE_KB * 11 / 10 ))
APPDATA_SIZE_H=$(du -sh "$APPDATA_PATH" 2>/dev/null | cut -f1)
OUTPUT_FREE_H=$(df -h "$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
# arithmetic and again with du -sh for the message — and walked $OUTPUT_DIR twice as well. On a
# container's appdata that is the expensive call in this script, paid twice to print a string.
# 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 "Estimated need: ~${APPDATA_SIZE_H} (×1.1 conservative) — available: ${OUTPUT_FREE_H}"
exit 1
+5 -3
View File
@@ -154,9 +154,11 @@ if [[ "$SHOW_STATUS" == true ]]; then
echo ""
if mountpoint -q "$RAMDISK_PATH" 2>/dev/null; then
USAGE=$(df -BG "$RAMDISK_PATH" | awk 'NR==2 {print $3}')
AVAIL=$(df -BG "$RAMDISK_PATH" | awk 'NR==2 {print $4}')
echo " $ICON_RAM Ramdisk: mounted — $USAGE used / $AVAIL available ✅"
if read -r _ USED_MB AVAIL_MB <<< "$(disk_df "$RAMDISK_PATH")" && [[ -n "$AVAIL_MB" ]]; then
echo " $ICON_RAM Ramdisk: mounted — $(format_mb "$USED_MB") used / $(format_mb "$AVAIL_MB") available ✅"
else
echo " $ICON_RAM Ramdisk: mounted — size unreadable"
fi
FILE_COUNT=$(find "$RAMDISK_PATH" -type f 2>/dev/null | wc -l)
echo " $ICON_RAM Active files on ramdisk: $FILE_COUNT"
else
+12 -6
View File
@@ -197,9 +197,13 @@ if [[ "$SHOW_STATUS" == true ]]; then
echo ""
if mountpoint -q "$RAMDISK_PATH" 2>/dev/null; then
USAGE=$(df -BG "$RAMDISK_PATH" | awk 'NR==2 {print $3}')
AVAIL=$(df -BG "$RAMDISK_PATH" | awk 'NR==2 {print $4}')
echo " $ICON_RAM Ramdisk: mounted — $USAGE used / $AVAIL available ✅"
# One df, not two — used and available come from the same read, so they cannot
# describe two different moments of a ramdisk that is actively being written to.
if read -r _ USED_MB AVAIL_MB <<< "$(disk_df "$RAMDISK_PATH")" && [[ -n "$AVAIL_MB" ]]; then
echo " $ICON_RAM Ramdisk: mounted — $(format_mb "$USED_MB") used / $(format_mb "$AVAIL_MB") available ✅"
else
echo " $ICON_RAM Ramdisk: mounted — size unreadable"
fi
else
echo " $ICON_RAM Ramdisk: NOT mounted"
fi
@@ -228,9 +232,11 @@ START=$(date +%s)
SETUP_SUCCESS=true
if mountpoint -q "$RAMDISK_PATH" 2>/dev/null; then
USAGE=$(df -BG "$RAMDISK_PATH" | awk 'NR==2 {print $3}')
AVAIL=$(df -BG "$RAMDISK_PATH" | awk 'NR==2 {print $4}')
log "Ramdisk already mounted — $USAGE used / $AVAIL available"
if read -r _ USED_MB AVAIL_MB <<< "$(disk_df "$RAMDISK_PATH")" && [[ -n "$AVAIL_MB" ]]; then
log "Ramdisk already mounted — $(format_mb "$USED_MB") used / $(format_mb "$AVAIL_MB") available"
else
log "Ramdisk already mounted — size unreadable"
fi
log "Skipping mount — verifying symlink and permissions"
else
if [[ "$DRY_RUN" == true ]]; then
+5 -3
View File
@@ -195,9 +195,11 @@ if [[ "$SHOW_STATUS" == true ]]; then
echo ""
if mountpoint -q "$RAMDISK_PATH" 2>/dev/null; then
USAGE=$(df -BG "$RAMDISK_PATH" | awk 'NR==2 {print $3}')
AVAIL=$(df -BG "$RAMDISK_PATH" | awk 'NR==2 {print $4}')
echo " $ICON_RAM Ramdisk: mounted — $USAGE used / $AVAIL available ✅"
if read -r _ USED_MB AVAIL_MB <<< "$(disk_df "$RAMDISK_PATH")" && [[ -n "$AVAIL_MB" ]]; then
echo " $ICON_RAM Ramdisk: mounted — $(format_mb "$USED_MB") used / $(format_mb "$AVAIL_MB") available ✅"
else
echo " $ICON_RAM Ramdisk: mounted — size unreadable"
fi
else
echo " $ICON_RAM Ramdisk: not mounted"
fi