Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix(store): allow memo/attachment deletion when local file is missing

Steven704503e5564a
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