A continuation of HomeBox the inventory and organization system built for the Home User
Fixes the document record being abandoned inside the database after an attachment is deleted. (#579)
EdWorth120629b1139ba24
diff --git a/backend/internal/core/services/service_items_attachments.go b/backend/internal/core/services/service_items_attachments.goindex 5ed2ea6e..9bc97d4f 100644--- a/backend/internal/core/services/service_items_attachments.go+++ b/backend/internal/core/services/service_items_attachments.go@@ -2,14 +2,12 @@ package servicesimport ("context"- "io"- "os"-"github.com/google/uuid""github.com/rs/zerolog/log""github.com/sysadminsmedia/homebox/backend/internal/data/ent""github.com/sysadminsmedia/homebox/backend/internal/data/ent/attachment""github.com/sysadminsmedia/homebox/backend/internal/data/repo"+ "io")func (svc *ItemService) AttachmentPath(ctx context.Context, attachmentID uuid.UUID) (*ent.Document, error) {@@ -77,14 +75,19 @@ func (svc *ItemService) AttachmentDelete(ctx context.Context, gid, itemID, attacreturn err}+ documentID := attachment.Edges.Document.GetID()+// Delete the attachmenterr = svc.repo.Attachments.Delete(ctx, attachmentID)if err != nil {return err}- // Remove File- err = os.Remove(attachment.Edges.Document.Path)+ // Delete the document, this function also removes the file+ err = svc.repo.Docs.Delete(ctx, documentID)+ if err != nil {+ return err+ }return err}