Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Aug 22, 2022
1 parent 5b7a094 commit dc16651
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
16 changes: 12 additions & 4 deletions pkg/share/manager/jsoncs3/jsoncs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ func (m *Manager) listSharesByIDs(ctx context.Context, user *userv1beta1.User, f
func (m *Manager) listCreatedShares(ctx context.Context, user *userv1beta1.User, filters []*collaboration.Filter) ([]*collaboration.Share, error) {
var ss []*collaboration.Share

m.CreatedCache.Sync(ctx, user.Id.OpaqueId)
if err := m.CreatedCache.Sync(ctx, user.Id.OpaqueId); err != nil {
return ss, err
}
for ssid, spaceShareIDs := range m.CreatedCache.List(user.Id.OpaqueId) {
storageID, spaceID, _ := shareid.Decode(ssid)
err := m.Cache.Sync(ctx, storageID, spaceID)
Expand Down Expand Up @@ -546,7 +548,9 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati

// first collect all spaceids the user has access to as a group member
for _, group := range user.Groups {
m.GroupReceivedCache.Sync(ctx, group)
if err := m.GroupReceivedCache.Sync(ctx, group); err != nil {
continue // ignore error, cache will be updated on next read
}
for ssid, spaceShareIDs := range m.GroupReceivedCache.List(group) {
// add a pending entry, the state will be updated
// when reading the received shares below if they have already been accepted or denied
Expand All @@ -565,7 +569,8 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati
}

// add all spaces the user has receved shares for, this includes mount points and share state for groups
m.UserReceivedStates.Sync(ctx, user.Id.OpaqueId)
_ = m.UserReceivedStates.Sync(ctx, user.Id.OpaqueId) // ignore error, cache will be updated on next read

if m.UserReceivedStates.ReceivedSpaces[user.Id.OpaqueId] != nil {
for ssid, rspace := range m.UserReceivedStates.ReceivedSpaces[user.Id.OpaqueId].Spaces {
if rs, ok := ssids[ssid]; ok {
Expand Down Expand Up @@ -616,7 +621,7 @@ func (m *Manager) convert(ctx context.Context, userID string, s *collaboration.S

storageID, spaceID, _ := shareid.Decode(s.Id.OpaqueId)

m.UserReceivedStates.Sync(ctx, userID)
_ = m.UserReceivedStates.Sync(ctx, userID) // ignore error, cache will be updated on next read
state := m.UserReceivedStates.Get(userID, storageID+"^"+spaceID, s.Id.GetOpaqueId())
if state != nil {
rs.State = state.State
Expand Down Expand Up @@ -686,6 +691,9 @@ func (m *Manager) UpdateReceivedShare(ctx context.Context, receivedShare *collab
err = m.UserReceivedStates.Add(ctx, userID.GetId().GetOpaqueId(), rs.Share.ResourceId.StorageId+"^"+rs.Share.ResourceId.SpaceId, rs)
// TODO try more often?
}
if err != nil {
return nil, err
}

return rs, nil
}
11 changes: 6 additions & 5 deletions pkg/share/manager/jsoncs3/jsoncs3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ var _ = Describe("Jsoncs3", func() {
Permissions: conversions.NewManagerRole().CS3ResourcePermissions(),
},
})
Expect(err).ToNot(HaveOccurred())
})

Describe("ListShares", func() {
Expand Down Expand Up @@ -338,7 +339,7 @@ var _ = Describe("Jsoncs3", func() {
cache.Shares[share.Id.OpaqueId].Permissions.Permissions.InitiateFileUpload = true
bytes, err := json.Marshal(cache)
Expect(err).ToNot(HaveOccurred())
storage.SimpleUpload(context.Background(), "storages/storageid/spaceid.json", bytes)
Expect(storage.SimpleUpload(context.Background(), "storages/storageid/spaceid.json", bytes)).To(Succeed())
Expect(err).ToNot(HaveOccurred())

// Reset providercache in memory
Expand Down Expand Up @@ -559,7 +560,7 @@ var _ = Describe("Jsoncs3", func() {
cache.Shares[share.Id.OpaqueId].Permissions.Permissions.InitiateFileUpload = true
bytes, err := json.Marshal(cache)
Expect(err).ToNot(HaveOccurred())
storage.SimpleUpload(context.Background(), "storages/storageid/spaceid.json", bytes)
Expect(storage.SimpleUpload(context.Background(), "storages/storageid/spaceid.json", bytes)).To(Succeed())
Expect(err).ToNot(HaveOccurred())

// Reset providercache in memory
Expand All @@ -579,9 +580,9 @@ var _ = Describe("Jsoncs3", func() {
Expect(len(shares)).To(Equal(1))

// Add a second cache to the provider cache so it can be referenced
m.Cache.Add(ctx, "storageid", "spaceid", "storageid^spaceid°secondshare", &collaboration.Share{
Expect(m.Cache.Add(ctx, "storageid", "spaceid", "storageid^spaceid°secondshare", &collaboration.Share{
Creator: user1.Id,
})
})).To(Succeed())

cache := sharecache.UserShareCache{
Mtime: time.Now(),
Expand Down Expand Up @@ -644,7 +645,7 @@ var _ = Describe("Jsoncs3", func() {
cache.Shares[share.Id.OpaqueId].Permissions.Permissions.InitiateFileUpload = true
bytes, err := json.Marshal(cache)
Expect(err).ToNot(HaveOccurred())
storage.SimpleUpload(context.Background(), "storages/storageid/spaceid.json", bytes)
Expect(storage.SimpleUpload(context.Background(), "storages/storageid/spaceid.json", bytes)).To(Succeed())
Expect(err).ToNot(HaveOccurred())

// Reset providercache in memory
Expand Down
18 changes: 9 additions & 9 deletions pkg/share/manager/jsoncs3/providercache/providercache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ var _ = Describe("Cache", func() {
s := c.Get(storageID, spaceID, shareID)
Expect(s).To(BeNil())

c.Add(ctx, storageID, spaceID, shareID, share1)
Expect(c.Add(ctx, storageID, spaceID, shareID, share1)).To(Succeed())

s = c.Get(storageID, spaceID, shareID)
Expect(s).ToNot(BeNil())
Expect(s).To(Equal(share1))
})

It("sets the mtime", func() {
c.Add(ctx, storageID, spaceID, shareID, share1)
Expect(c.Add(ctx, storageID, spaceID, shareID, share1)).To(Succeed())
Expect(c.Providers[storageID].Spaces[spaceID].Mtime).ToNot(Equal(time.Time{}))
})

It("updates the mtime", func() {
c.Add(ctx, storageID, spaceID, shareID, share1)
Expect(c.Add(ctx, storageID, spaceID, shareID, share1)).To(Succeed())
old := c.Providers[storageID].Spaces[spaceID].Mtime
c.Add(ctx, storageID, spaceID, shareID, share1)
Expect(c.Add(ctx, storageID, spaceID, shareID, share1)).To(Succeed())
Expect(c.Providers[storageID].Spaces[spaceID].Mtime).ToNot(Equal(old))
})
})
Expand All @@ -115,16 +115,16 @@ var _ = Describe("Cache", func() {
Expect(s).ToNot(BeNil())
Expect(s).To(Equal(share1))

c.Remove(ctx, storageID, spaceID, shareID)
Expect(c.Remove(ctx, storageID, spaceID, shareID)).To(Succeed())

s = c.Get(storageID, spaceID, shareID)
Expect(s).To(BeNil())
})

It("updates the mtime", func() {
c.Add(ctx, storageID, spaceID, shareID, share1)
Expect(c.Add(ctx, storageID, spaceID, shareID, share1)).To(Succeed())
old := c.Providers[storageID].Spaces[spaceID].Mtime
c.Remove(ctx, storageID, spaceID, shareID)
Expect(c.Remove(ctx, storageID, spaceID, shareID)).To(Succeed())
Expect(c.Providers[storageID].Spaces[spaceID].Mtime).ToNot(Equal(old))
})
})
Expand Down Expand Up @@ -167,7 +167,7 @@ var _ = Describe("Cache", func() {
s := c.Get(storageID, spaceID, shareID)
Expect(s).To(BeNil())

c.Sync(ctx, storageID, spaceID)
Expect(c.Sync(ctx, storageID, spaceID)).To(Succeed())

s = c.Get(storageID, spaceID, shareID)
Expect(s).ToNot(BeNil())
Expand All @@ -184,7 +184,7 @@ var _ = Describe("Cache", func() {
},
},
}
c.Sync(ctx, storageID, spaceID) // Sync from disk won't happen because in-memory mtime is later than on disk
Expect(c.Sync(ctx, storageID, spaceID)).To(Succeed()) // Sync from disk won't happen because in-memory mtime is later than on disk

s = c.Get(storageID, spaceID, shareID)
Expect(s).To(BeNil())
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TSToTime(ts *types.Timestamp) time.Time {
// TimeToTS converts Go's time.Time to a protobuf Timestamp.
func TimeToTS(t time.Time) *types.Timestamp {
return &types.Timestamp{
Seconds: uint64(t.Unix()), // implicity returns UTC
Seconds: uint64(t.Unix()), // implicitly returns UTC
Nanos: uint32(t.Nanosecond()),
}
}
Expand Down

0 comments on commit dc16651

Please sign in to comment.