From 46c53b4e7cf36956e03883602aee12c154025196 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 2 Sep 2019 23:29:21 -0600 Subject: [PATCH] Delete quarantined content without deleting the DB record Fixes https://github.com/turt2live/matrix-media-repo/issues/197 --- .../maintainance_controller.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/controllers/maintenance_controller/maintainance_controller.go b/controllers/maintenance_controller/maintainance_controller.go index cdc70349..34cc6409 100644 --- a/controllers/maintenance_controller/maintainance_controller.go +++ b/controllers/maintenance_controller/maintainance_controller.go @@ -289,11 +289,25 @@ func doPurge(media *types.Media, ctx context.Context, log *logrus.Entry) error { } metadataDb := storage.GetDatabase().GetMetadataStore(ctx, log) - err = metadataDb.ReserveMediaId(media.Origin, media.MediaId, "purged / deleted") + + reserved, err := metadataDb.IsReserved(media.Origin, media.MediaId) if err != nil { return err } + if !reserved { + err = metadataDb.ReserveMediaId(media.Origin, media.MediaId, "purged / deleted") + if err != nil { + return err + } + } + + // Don't delete the media record itself if it is quarantined. If we delete it, the media + // becomes not-quarantined so we'll leave it and let it 404 in the datastores. + if media.Quarantined { + return nil + } + mediaDb := storage.GetDatabase().GetMediaStore(ctx, log) err = mediaDb.Delete(media.Origin, media.MediaId) if err != nil {