Skip to content

Commit

Permalink
Fixed issue where removing a video file would block because of prompt…
Browse files Browse the repository at this point in the history
… from `rm`. Also added error checking on files/folders removal.
  • Loading branch information
jlesage committed Dec 13, 2023
1 parent edab0b8 commit 0f66829
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions rootfs/etc/services.d/autovideoconverter/run
Original file line number Diff line number Diff line change
Expand Up @@ -356,20 +356,33 @@ process_video() {
echo "$video $hash" >> "$SUCCESSFUL_CONVERSIONS"
if is-bool-val-false "$AC_KEEP_SOURCE"; then
if is-bool-val-false "${AUTOMATED_CONVERSION_USE_TRASH:-0}"; then
rm -r "$video"
log "Removed $video'."
log "Removing '$video'..."
rm -rf "$video"
if [ $? -eq 0 ]; then
log "Removed '$video'."
else
log "ERROR: Could not remove '$video'."
fi
else
VIDEO_TRASH_PATH="/trash/${video#"$wf"}"
mkdir -p "$(dirname "$VIDEO_TRASH_PATH")"
log "Moving $video to trash directory..."
log "Moving '$video' to trash directory..."
mv "$video" "$VIDEO_TRASH_PATH"
log "Moved $video to trash directory."
if [ $? -eq 0 ]; then
log "Moved '$video' to trash directory."
else
log "ERROR: Could not move '$video' to trash directory."
fi
fi
# Remove directory if empty (hidden files/folders are ignored).
videodir="$(dirname "$video")"
while [ "$videodir" != "$wf" ] && [ -z "$(ls "$videodir")" ]; do
log "Removed directory '$videodir'."
rm -rf "$videodir"
if [ $? -eq 0 ]; then
log "Removed directory '$videodir'."
else
log "ERROR: Could not remove directory '$videodir'."
fi
videodir="$(dirname "$videodir")"
done
fi
Expand Down

0 comments on commit 0f66829

Please sign in to comment.