Skip to content
8 changes: 7 additions & 1 deletion internal/arrs/registrar/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
"golift.io/starr/sonarr"
)

// AltmountDownloadClientName is the name AltMount registers itself under as a
// SABnzbd-compatible download client in Radarr/Sonarr/Lidarr/etc. Other code
// (e.g. the queue cleanup worker) imports this to distinguish AltMount's own
// queue items from those owned by other download clients.
const AltmountDownloadClientName = "AltMount (SABnzbd)"

type Manager struct {
instances *instances.Manager
clients *clients.Manager
Expand Down Expand Up @@ -366,7 +372,7 @@ func (m *Manager) EnsureWebhookRegistration(ctx context.Context, altmountURL str
// EnsureDownloadClientRegistration ensures that AltMount is registered as a SABnzbd download client in all enabled ARR instances
func (m *Manager) EnsureDownloadClientRegistration(ctx context.Context, altmountHost string, altmountPort int, urlBase string, apiKey string) error {
allInstances := m.instances.GetAllInstances()
clientName := "AltMount (SABnzbd)"
clientName := AltmountDownloadClientName

slog.InfoContext(ctx, "Ensuring AltMount download client registration in ARR instances",
"host", altmountHost,
Expand Down
15 changes: 15 additions & 0 deletions internal/arrs/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/javi11/altmount/internal/arrs/clients"
"github.com/javi11/altmount/internal/arrs/instances"
"github.com/javi11/altmount/internal/arrs/model"
"github.com/javi11/altmount/internal/arrs/registrar"
"github.com/javi11/altmount/internal/config"
"github.com/javi11/altmount/internal/database"
"golift.io/starr"
Expand Down Expand Up @@ -179,6 +180,13 @@ func (w *Worker) cleanupRadarrQueue(ctx context.Context, instance *model.ConfigI

var idsToRemove []int64
for _, q := range queue.Records {
// Only operate on queue items owned by AltMount's registered download client.
// Items from other clients (qBittorrent, real SABnzbd, etc.) may reference
// paths AltMount cannot see and must never be touched — see issue #523.
if q.DownloadClient != registrar.AltmountDownloadClientName {
continue
}

// Strategy 1: Ghost detection — cleanup already-imported files
if w.checkGhostByImportHistory(ctx, q.OutputPath, cfg, instance.Name, q.Title) {
idsToRemove = append(idsToRemove, q.ID)
Expand Down Expand Up @@ -301,6 +309,13 @@ func (w *Worker) cleanupSonarrQueue(ctx context.Context, instance *model.ConfigI

var idsToRemove []int64
for _, q := range queue.Records {
// Only operate on queue items owned by AltMount's registered download client.
// Items from other clients (qBittorrent, real SABnzbd, etc.) may reference
// paths AltMount cannot see and must never be touched — see issue #523.
if q.DownloadClient != registrar.AltmountDownloadClientName {
continue
}

// Strategy 1: Immediate cleanup for already imported files
if w.checkGhostByImportHistory(ctx, q.OutputPath, cfg, instance.Name, q.Title) {
idsToRemove = append(idsToRemove, q.ID)
Expand Down
Loading