Merge pull request #6507 from owncloud/update-reva

[full-ci] update reva
This commit is contained in:
Michael Barz
2023-06-13 09:29:44 +02:00
committed by GitHub
13 changed files with 132 additions and 35 deletions

View File

@@ -0,0 +1,5 @@
Enhancement: Update reva
Update reva to latest edge
https://github.com/owncloud/ocis/pull/6507

2
go.mod
View File

@@ -13,7 +13,7 @@ require (
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/coreos/go-oidc/v3 v3.6.0
github.com/cs3org/go-cs3apis v0.0.0-20230516150832-730ac860c71d
github.com/cs3org/reva/v2 v2.14.1-0.20230608155229-cf1aa9641f93
github.com/cs3org/reva/v2 v2.14.1-0.20230612154151-5fbd21b664e1
github.com/disintegration/imaging v1.6.2
github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e
github.com/egirna/icap-client v0.1.1

2
go.sum
View File

@@ -631,6 +631,8 @@ github.com/crewjam/saml v0.4.13 h1:TYHggH/hwP7eArqiXSJUvtOPNzQDyQ7vwmwEqlFWhMc=
github.com/crewjam/saml v0.4.13/go.mod h1:igEejV+fihTIlHXYP8zOec3V5A8y3lws5bQBFsTm4gA=
github.com/cs3org/reva/v2 v2.14.1-0.20230608155229-cf1aa9641f93 h1:yRhkp28pdpSbEDX+XQtq5ZiZ8jLMRnmuEKwFj9AlzfY=
github.com/cs3org/reva/v2 v2.14.1-0.20230608155229-cf1aa9641f93/go.mod h1:E32krZG159YflDSjDWfx/QGIC2529PS5LiPnGNHu3d0=
github.com/cs3org/reva/v2 v2.14.1-0.20230612154151-5fbd21b664e1 h1:LN4ADWFL8SbuVDCN5d5b63swaEA8D7Ojt39AgUv46qA=
github.com/cs3org/reva/v2 v2.14.1-0.20230612154151-5fbd21b664e1/go.mod h1:E32krZG159YflDSjDWfx/QGIC2529PS5LiPnGNHu3d0=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=

View File

@@ -129,9 +129,13 @@ type ShareData struct {
// The type of the object being shared. This can be one of 'file' or 'folder'.
ItemType string `json:"item_type" xml:"item_type"`
// The RFC2045-compliant mimetype of the file.
MimeType string `json:"mimetype" xml:"mimetype"`
StorageID string `json:"storage_id" xml:"storage_id"`
Storage uint64 `json:"storage" xml:"storage"`
MimeType string `json:"mimetype" xml:"mimetype"`
// The space ID of the original file location
SpaceID string `json:"space_id" xml:"space_id"`
// The space alias of the original file location
SpaceAlias string `json:"space_alias" xml:"space_alias"`
StorageID string `json:"storage_id" xml:"storage_id"`
Storage uint64 `json:"storage" xml:"storage"`
// The unique node id of the item being shared.
ItemSource string `json:"item_source" xml:"item_source"`
// The unique node id of the item being shared. For legacy reasons item_source and file_source attributes have the same value.

View File

@@ -1209,6 +1209,11 @@ func (h *Handler) addFileInfo(ctx context.Context, s *conversions.ShareData, inf
if s.UIDOwner == "" && owner != nil {
s.UIDOwner = owner.GetOpaqueId()
}
if info.GetSpace().GetRoot() != nil {
s.SpaceID = storagespace.FormatResourceID(*info.GetSpace().GetRoot())
}
s.SpaceAlias = utils.ReadPlainFromOpaque(info.GetSpace().GetOpaque(), "spaceAlias")
}
// mustGetIdentifiers always returns a struct with identifiers, if the user or group could not be found they will all be empty

View File

@@ -309,8 +309,6 @@ func (m *Manager) Share(ctx context.Context, md *provider.ResourceInfo, g *colla
Grantee: g.Grantee,
}
m.Lock()
defer m.Unlock()
_, err := m.getByKey(ctx, key)
if err == nil {
// share already exists
@@ -468,8 +466,6 @@ func (m *Manager) GetShare(ctx context.Context, ref *collaboration.ShareReferenc
return nil, err
}
m.Lock()
defer m.Unlock()
s, err := m.get(ctx, ref)
if err != nil {
return nil, err
@@ -521,8 +517,6 @@ func (m *Manager) Unshare(ctx context.Context, ref *collaboration.ShareReference
return err
}
m.Lock()
defer m.Unlock()
user := ctxpkg.ContextMustGetUser(ctx)
s, err := m.get(ctx, ref)
@@ -547,9 +541,6 @@ func (m *Manager) UpdateShare(ctx context.Context, ref *collaboration.ShareRefer
return nil, err
}
m.Lock()
defer m.Unlock()
var toUpdate *collaboration.Share
if ref != nil {
@@ -598,6 +589,8 @@ func (m *Manager) UpdateShare(ctx context.Context, ref *collaboration.ShareRefer
toUpdate.Mtime = utils.TSNow()
// Update provider cache
unlock := m.Cache.LockSpace(toUpdate.ResourceId.SpaceId)
defer unlock()
err := m.Cache.Persist(ctx, toUpdate.ResourceId.StorageId, toUpdate.ResourceId.SpaceId)
// when persisting fails
if _, ok := err.(errtypes.IsPreconditionFailed); ok {
@@ -629,9 +622,6 @@ func (m *Manager) ListShares(ctx context.Context, filters []*collaboration.Filte
return nil, err
}
m.Lock()
defer m.Unlock()
user := ctxpkg.ContextMustGetUser(ctx)
if len(share.FilterFiltersByType(filters, collaboration.Filter_TYPE_RESOURCE_ID)) > 0 {
@@ -775,9 +765,6 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati
return nil, err
}
m.Lock()
defer m.Unlock()
user := ctxpkg.ContextMustGetUser(ctx)
ssids := map[string]*receivedsharecache.Space{}
@@ -958,8 +945,6 @@ func (m *Manager) getReceived(ctx context.Context, ref *collaboration.ShareRefer
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "getReceived")
defer span.End()
m.Lock()
defer m.Unlock()
s, err := m.get(ctx, ref)
if err != nil {
return nil, err
@@ -1001,9 +986,6 @@ func (m *Manager) UpdateReceivedShare(ctx context.Context, receivedShare *collab
return nil, err
}
m.Lock()
defer m.Unlock()
for i := range fieldMask.Paths {
switch fieldMask.Paths[i] {
case "state":

View File

@@ -25,6 +25,7 @@ import (
"os"
"path"
"path/filepath"
"sync"
"time"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
@@ -42,6 +43,9 @@ const tracerName = "providercache"
// Cache holds share information structured by provider and space
type Cache struct {
lockMapLock sync.Mutex
lockMap map[string]*sync.Mutex
Providers map[string]*Spaces
storage metadata.Storage
@@ -100,17 +104,37 @@ func (s *Shares) UnmarshalJSON(data []byte) error {
return nil
}
// LockSpace locks the cache for a given space and returns an unlock function
func (c *Cache) LockSpace(spaceID string) func() {
lock := c.lockMap[spaceID]
if lock == nil {
c.lockMapLock.Lock()
lock = c.lockMap[spaceID]
if lock == nil {
c.lockMap[spaceID] = &sync.Mutex{}
lock = c.lockMap[spaceID]
}
c.lockMapLock.Unlock()
}
lock.Lock()
return func() { lock.Unlock() }
}
// New returns a new Cache instance
func New(s metadata.Storage, ttl time.Duration) Cache {
return Cache{
Providers: map[string]*Spaces{},
storage: s,
ttl: ttl,
lockMap: map[string]*sync.Mutex{},
}
}
// Add adds a share to the cache
func (c *Cache) Add(ctx context.Context, storageID, spaceID, shareID string, share *collaboration.Share) error {
unlock := c.LockSpace(spaceID)
defer unlock()
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Add")
defer span.End()
span.SetAttributes(attribute.String("cs3.storageid", storageID), attribute.String("cs3.spaceid", spaceID), attribute.String("cs3.shareid", shareID))
@@ -131,6 +155,9 @@ func (c *Cache) Add(ctx context.Context, storageID, spaceID, shareID string, sha
// Remove removes a share from the cache
func (c *Cache) Remove(ctx context.Context, storageID, spaceID, shareID string) error {
unlock := c.LockSpace(spaceID)
defer unlock()
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Remove")
defer span.End()
span.SetAttributes(attribute.String("cs3.storageid", storageID), attribute.String("cs3.spaceid", spaceID), attribute.String("cs3.shareid", shareID))
@@ -212,6 +239,9 @@ func (c *Cache) Persist(ctx context.Context, storageID, spaceID string) error {
// Sync updates the in-memory data with the data from the storage if it is outdated
func (c *Cache) Sync(ctx context.Context, storageID, spaceID string) error {
unlock := c.LockSpace(spaceID)
defer unlock()
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Sync")
defer span.End()

View File

@@ -24,6 +24,7 @@ import (
"fmt"
"path"
"path/filepath"
"sync"
"time"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
@@ -43,6 +44,9 @@ const tracerName = "receivedsharecache"
// It functions as an in-memory cache with a persistence layer
// The storage is sharded by user
type Cache struct {
lockMapLock sync.Mutex
lockMap map[string]*sync.Mutex
ReceivedSpaces map[string]*Spaces
storage metadata.Storage
@@ -75,11 +79,30 @@ func New(s metadata.Storage, ttl time.Duration) Cache {
ReceivedSpaces: map[string]*Spaces{},
storage: s,
ttl: ttl,
lockMap: map[string]*sync.Mutex{},
}
}
func (c *Cache) lockUser(userID string) func() {
lock := c.lockMap[userID]
if lock == nil {
c.lockMapLock.Lock()
lock = c.lockMap[userID]
if lock == nil {
c.lockMap[userID] = &sync.Mutex{}
lock = c.lockMap[userID]
}
c.lockMapLock.Unlock()
}
lock.Lock()
return func() { lock.Unlock() }
}
// Add adds a new entry to the cache
func (c *Cache) Add(ctx context.Context, userID, spaceID string, rs *collaboration.ReceivedShare) error {
unlock := c.lockUser(userID)
defer unlock()
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Add")
defer span.End()
span.SetAttributes(attribute.String("cs3.userid", userID), attribute.String("cs3.spaceid", spaceID))
@@ -103,7 +126,7 @@ func (c *Cache) Add(ctx context.Context, userID, spaceID string, rs *collaborati
MountPoint: rs.MountPoint,
}
return c.Persist(ctx, userID)
return c.persist(ctx, userID)
}
// Get returns one entry from the cache
@@ -116,6 +139,9 @@ func (c *Cache) Get(userID, spaceID, shareID string) *State {
// Sync updates the in-memory data with the data from the storage if it is outdated
func (c *Cache) Sync(ctx context.Context, userID string) error {
unlock := c.lockUser(userID)
defer unlock()
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Sync")
defer span.End()
span.SetAttributes(attribute.String("cs3.userid", userID))
@@ -172,8 +198,8 @@ func (c *Cache) Sync(ctx context.Context, userID string) error {
return nil
}
// Persist persists the data for one user to the storage
func (c *Cache) Persist(ctx context.Context, userID string) error {
// persist persists the data for one user to the storage
func (c *Cache) persist(ctx context.Context, userID string) error {
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Persist")
defer span.End()
span.SetAttributes(attribute.String("cs3.userid", userID))

View File

@@ -24,6 +24,7 @@ import (
"fmt"
"path"
"path/filepath"
"sync"
"time"
"github.com/cs3org/reva/v2/pkg/appctx"
@@ -42,6 +43,9 @@ const tracerName = "sharecache"
// It functions as an in-memory cache with a persistence layer
// The storage is sharded by user/group
type Cache struct {
lockMapLock sync.Mutex
lockMap map[string]*sync.Mutex
UserShares map[string]*UserShareCache
storage metadata.Storage
@@ -64,6 +68,21 @@ type SpaceShareIDs struct {
IDs map[string]struct{}
}
func (c *Cache) lockUser(userID string) func() {
lock := c.lockMap[userID]
if lock == nil {
c.lockMapLock.Lock()
lock = c.lockMap[userID]
if lock == nil {
c.lockMap[userID] = &sync.Mutex{}
lock = c.lockMap[userID]
}
c.lockMapLock.Unlock()
}
lock.Lock()
return func() { lock.Unlock() }
}
// New returns a new Cache instance
func New(s metadata.Storage, namespace, filename string, ttl time.Duration) Cache {
return Cache{
@@ -72,11 +91,15 @@ func New(s metadata.Storage, namespace, filename string, ttl time.Duration) Cach
namespace: namespace,
filename: filename,
ttl: ttl,
lockMap: map[string]*sync.Mutex{},
}
}
// Add adds a share to the cache
func (c *Cache) Add(ctx context.Context, userid, shareID string) error {
unlock := c.lockUser(userid)
defer unlock()
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Add")
defer span.End()
span.SetAttributes(attribute.String("cs3.userid", userid), attribute.String("cs3.shareid", shareID))
@@ -104,6 +127,9 @@ func (c *Cache) Add(ctx context.Context, userid, shareID string) error {
// Remove removes a share for the given user
func (c *Cache) Remove(ctx context.Context, userid, shareID string) error {
unlock := c.lockUser(userid)
defer unlock()
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Remove")
defer span.End()
span.SetAttributes(attribute.String("cs3.userid", userid), attribute.String("cs3.shareid", shareID))
@@ -147,6 +173,9 @@ func (c *Cache) List(userid string) map[string]SpaceShareIDs {
// Sync updates the in-memory data with the data from the storage if it is outdated
func (c *Cache) Sync(ctx context.Context, userID string) error {
unlock := c.lockUser(userID)
defer unlock()
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Sync")
defer span.End()
span.SetAttributes(attribute.String("cs3.userid", userID))

View File

@@ -948,11 +948,11 @@ func (n *Node) IsDisabled() bool {
// GetTreeSize reads the treesize from the extended attributes
func (n *Node) GetTreeSize() (treesize uint64, err error) {
s, err := n.XattrInt64(prefixes.TreesizeAttr)
s, err := n.XattrUint64(prefixes.TreesizeAttr)
if err != nil {
return 0, err
}
return uint64(s), nil
return s, nil
}
// SetTreeSize writes the treesize to the extended attributes

View File

@@ -174,3 +174,12 @@ func (n *Node) XattrInt64(key string) (int64, error) {
}
return strconv.ParseInt(b, 10, 64)
}
// XattrUint64 returns the uint64 representation of an attribute
func (n *Node) XattrUint64(key string) (uint64, error) {
b, err := n.XattrString(key)
if err != nil {
return 0, err
}
return strconv.ParseUint(b, 10, 64)
}

View File

@@ -794,12 +794,17 @@ func (t *Tree) Propagate(ctx context.Context, n *node.Node, sizeDiff int64) (err
}
case err != nil:
return err
case sizeDiff > 0:
newSize = treeSize + uint64(sizeDiff)
case uint64(-sizeDiff) > treeSize:
// The sizeDiff is larger than the current treesize. Which would result in
// a negative new treesize. Something must have gone wrong with the accounting.
// Reset the current treesize to 0.
sublog.Error().Uint64("treeSize", treeSize).Int64("sizeDiff", sizeDiff).
Msg("Error when updating treesize of parent node. Updated treesize < 0. Reestting to 0")
newSize = 0
default:
if sizeDiff > 0 {
newSize = treeSize + uint64(sizeDiff)
} else {
newSize = treeSize - uint64(-sizeDiff)
}
newSize = treeSize - uint64(-sizeDiff)
}
// update the tree size of the node

2
vendor/modules.txt vendored
View File

@@ -352,7 +352,7 @@ github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1
github.com/cs3org/go-cs3apis/cs3/storage/registry/v1beta1
github.com/cs3org/go-cs3apis/cs3/tx/v1beta1
github.com/cs3org/go-cs3apis/cs3/types/v1beta1
# github.com/cs3org/reva/v2 v2.14.1-0.20230608155229-cf1aa9641f93
# github.com/cs3org/reva/v2 v2.14.1-0.20230612154151-5fbd21b664e1
## explicit; go 1.20
github.com/cs3org/reva/v2/cmd/revad/internal/grace
github.com/cs3org/reva/v2/cmd/revad/runtime