Skip to content

Leftover-folder cleanup is skipped silently when the item is not tracked in Radarr/Sonarr #3370

Description

@enoch85

Summary

When an item is not tracked in Radarr/Sonarr, the arr action handlers fall back to deleting the media file through the media server. The leftover-folder cleanup is never invoked on that path, so the media file is removed while the folder (subtitles, trailers, nfo, artwork) stays behind. Nothing is logged to say the cleanup was skipped, so with the option enabled it silently does not run.

Where

folderCleanup.cleanupAfterDelete is only called inside the Radarr-tracked UNMONITOR_DELETE_ALL branch:

  • apps/server/src/modules/actions/radarr-action-handler.ts#L143-L150 - cleanup runs here
  • apps/server/src/modules/actions/radarr-action-handler.ts#L201-L207 - "not found in Radarr" fallback calls mediaServer.deleteFromDisk() and returns, no cleanup, no warning

The Sonarr handler has the same shape at apps/server/src/modules/actions/sonarr-action-handler.ts#L117-L119.

Why it is not a one-line fix

collectCleanupInputs derives every fence the cleanup needs from Radarr (apps/server/src/modules/actions/radarr-action-handler.ts#L233-L272):

  • rootFolderPaths - the roots it may act inside
  • deletedFilePaths - proof the folder is the one just emptied
  • otherItemPaths - the other movie folders it must not touch

With no arr entry, none of those are available, so the cleanup cannot simply be called from the fallback branch. Doing so without fences would mean an unfenced fs.rm.

Options

  1. Derive the fences from the media server instead: the item's own file paths, the library root folders, and the sibling item paths for the "do not touch another item's folder" fence.
  2. If (1) is out of scope for now, log a warning in the fallback branch so a skipped cleanup is visible rather than silent.

Observed

Jellyfin 10.11.11, collection type movie, arrAction = UNMONITOR_DELETE_ALL, cleanupLeftoverFolders = 1:

[RadarrActionHandler] Couldn't find movie in Radarr using resolved external IDs [TMDB:763164] for media server ID 9614097b... Attempting to remove from the filesystem via media server.
[JellyfinAdapterService] Successfully deleted Jellyfin item 9614097b... from disk

The media file was removed, the folder was left in place, and no cleanup line was logged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions