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.
This commit is contained in:
Steven 2026-02-23 10:26:40 +08:00
parent 17fc8383df
commit 704503e556
2 changed files with 4 additions and 1 deletions

View File

@ -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,

View File

@ -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