From 73356cbbc12a562f96987b61c3822a82c6932a5f Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Thu, 26 Nov 2020 18:05:43 +0530 Subject: [PATCH] Fix minor bugs in publicshare pkg --- pkg/publicshare/manager/json/json.go | 13 +++++++++---- pkg/publicshare/manager/memory/memory.go | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/publicshare/manager/json/json.go b/pkg/publicshare/manager/json/json.go index 9e4c1a17021..4d61b297517 100644 --- a/pkg/publicshare/manager/json/json.go +++ b/pkg/publicshare/manager/json/json.go @@ -363,16 +363,19 @@ func (m *manager) ListPublicShares(ctx context.Context, u *user.User, filters [] // RevokePublicShare undocumented. func (m *manager) RevokePublicShare(ctx context.Context, u *user.User, ref *link.PublicShareReference) error { m.mutex.Lock() - defer m.mutex.Unlock() - db, err := m.readDb() if err != nil { return err } + m.mutex.Unlock() switch { - case ref.GetId().OpaqueId != "": - delete(db, ref.GetId().OpaqueId) + case ref.GetId() != nil && ref.GetId().OpaqueId != "": + if _, ok := db[ref.GetId().OpaqueId]; ok { + delete(db, ref.GetId().OpaqueId) + } else { + return errors.New("reference does not exist") + } case ref.GetToken() != "": share, err := m.getByToken(ctx, ref.GetToken()) if err != nil { @@ -383,6 +386,8 @@ func (m *manager) RevokePublicShare(ctx context.Context, u *user.User, ref *link return errors.New("reference does not exist") } + m.mutex.Lock() + defer m.mutex.Unlock() return m.writeDb(db) } diff --git a/pkg/publicshare/manager/memory/memory.go b/pkg/publicshare/manager/memory/memory.go index e8c3372785e..6f3e8f14219 100644 --- a/pkg/publicshare/manager/memory/memory.go +++ b/pkg/publicshare/manager/memory/memory.go @@ -194,7 +194,7 @@ func (m *manager) ListPublicShares(ctx context.Context, u *user.User, filters [] func (m *manager) RevokePublicShare(ctx context.Context, u *user.User, ref *link.PublicShareReference) error { // check whether the reference exists switch { - case ref.GetId().OpaqueId != "": + case ref.GetId() != nil && ref.GetId().OpaqueId != "": s, err := m.getPublicShareByTokenID(ctx, *ref.GetId()) if err != nil { return errors.New("reference does not exist")