Skip to content

Commit

Permalink
Fix minor bugs in publicshare pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Nov 26, 2020
1 parent ebc4459 commit 73356cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions pkg/publicshare/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/publicshare/manager/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 73356cb

Please sign in to comment.