From 704503e5564a10ee431ef15a09ae01b3d0ca88e3 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 23 Feb 2026 10:26:40 +0800 Subject: [PATCH] fix(store): allow memo/attachment deletion when local file is missing Fixes two bugs reported in #5603: 1. store/attachment.go: ignore os.ErrNotExist when removing a local attachment file so that a missing file on disk (broken state from failed uploads) no longer blocks deletion of the DB record, allowing memos referencing corrupt attachments to be deleted normally. 2. memo_attachment_service.go: add nil guard on GetAttachment result before dereferencing it in SetMemoAttachments, preventing a nil pointer panic when an attachment UID no longer exists in the DB. --- server/router/api/v1/memo_attachment_service.go | 3 +++ store/attachment.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/server/router/api/v1/memo_attachment_service.go b/server/router/api/v1/memo_attachment_service.go index 153f1aa80..d9aa0a3ee 100644 --- a/server/router/api/v1/memo_attachment_service.go +++ b/server/router/api/v1/memo_attachment_service.go @@ -76,6 +76,9 @@ func (s *APIV1Service) SetMemoAttachments(ctx context.Context, request *v1pb.Set if err != nil { return nil, status.Errorf(codes.Internal, "failed to get attachment: %v", err) } + if tempAttachment == nil { + return nil, status.Errorf(codes.NotFound, "attachment not found: %s", attachmentUID) + } updatedTs := time.Now().Unix() + int64(index) if err := s.Store.UpdateAttachment(ctx, &store.UpdateAttachment{ ID: tempAttachment.ID, diff --git a/store/attachment.go b/store/attachment.go index cd3ac2a16..f9897d08e 100644 --- a/store/attachment.go +++ b/store/attachment.go @@ -129,7 +129,7 @@ func (s *Store) DeleteAttachment(ctx context.Context, delete *DeleteAttachment) p = filepath.Join(s.profile.Data, p) } err := os.Remove(p) - if err != nil { + if err != nil && !os.IsNotExist(err) { return errors.Wrap(err, "failed to delete local file") } return nil