diff --git a/Transcodes/transcode_cleanup.sh b/Transcodes/transcode_cleanup.sh index 5b451d6..9f3b880 100755 --- a/Transcodes/transcode_cleanup.sh +++ b/Transcodes/transcode_cleanup.sh @@ -24,6 +24,14 @@ # lsof is called once per location to build a complete open-file map. All subsequent # checks are O(1) lookups against that map — thousands of files, one lsof call. # +# find -printf Instead of Per-File stat/basename (2026-07-17) +# Same fork-elimination principle as above, applied to the file-processing loop. find +# already has to stat() every entry to know it's -type f, so -printf '%s %p' gets the +# size for free during the walk instead of a separate stat fork per file. basename was +# also forking per file in the dry-run log line -- replaced with parameter expansion +# (${file##*/}). Same class of bug found and measured (~28-185x per call) in the arr +# cleanup scripts' classification loops the same day. +# # No Session-Aware Cleanup # ffmpeg generates folder names independently of the media server API session IDs. # There is no reliable correlation between API session IDs and transcoding-temp @@ -200,8 +208,11 @@ cleanup_location() { log "$files_streaming files currently open in $label" fi - # Process aged files - while IFS= read -r file; do + # Process aged files. -printf gets size directly from find's own stat() during the walk + # instead of a separate stat fork per file (2026-07-17, same fix as the arr cleanup + # scripts) — mtime isn't needed here since -mmin above already did the age filtering. + local file_size file + while read -r file_size file; do [[ -z "$file" ]] && continue # O(1) open file check — in-memory map @@ -211,11 +222,8 @@ cleanup_location() { continue fi - local file_size - file_size=$(stat -c%s "$file" 2>/dev/null || echo 0) - if [[ "$DRY_RUN" == true ]]; then - log "DRY RUN — would delete: $(basename "$file")" + log "DRY RUN — would delete: ${file##*/}" (( files_skipped++ )) else if rm -f "$file" 2>/dev/null; then @@ -228,7 +236,7 @@ cleanup_location() { fi fi - done < <(find "$location" -type f -mmin +"$max_age" 2>/dev/null) + done < <(find "$location" -type f -mmin +"$max_age" -printf '%s %p\n' 2>/dev/null) # Remove empty directories older than TRANSCODE_ORPHAN_AGE — but NEVER remove # transcoding-temp. Age gate avoids deleting a session folder ffmpeg just