fix(permissions): bump reva

This commit is contained in:
Alex Ababii committed 2026-11-20 17:27:32 +01:00
1 parent 3477784431
commit 38e836b956
14 files changed
+135 -423

No files matched your search

+1 -4
View File
@@ -68,7 +68,7 @@ require (
github.com/open-policy-agent/opa v1.21.1
github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89
github.com/opencloud-eu/libre-graph-api-go v1.0.9-0.20261119152805-1a7a500a264e
github.com/opencloud-eu/reva/v3 v3.0.2-0.20261119154313-aa77b15bccec
github.com/opencloud-eu/reva/v3 v3.0.2-0.20261120162312-20c6e78244d3
github.com/opensearch-project/opensearch-go/v4 v4.7.3
github.com/orcaman/concurrent-map v1.0.0
github.com/pkg/errors v0.9.1
@@ -404,6 +404,3 @@ replace go-micro.dev/v4 => github.com/butonic/go-micro/v4 v4.11.4-0.202609292135
exclude github.com/mattn/go-sqlite3 v2.0.3+incompatible
replace github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/opencloud-eu/go-micro-plugins/v4/store/nats-js-kv v0.0.0-20250512152754-23325793059a
// TEMP: remove once reva#963 (feat/personal_space_permissions) is released and bump reva to the release version
replace github.com/opencloud-eu/reva/v3 => github.com/maki5/reva/v3 v3.0.0-20261117123005-56afac944faf
+2 -4
View File
@@ -642,8 +642,6 @@ github.com/lufia/plan9stats v0.0.0-20260330125221-c963978e514e h1:Q6MvJtQK/iRcRt
github.com/lufia/plan9stats v0.0.0-20260330125221-c963978e514e/go.mod h1:autxFIvghDt3jPTLoqZ9OZ7s9qTGNAWmYCjVFWPX/zg=
github.com/magiconair/properties v1.8.10 h1:s31yESBquKXCV9a/ScB3ESkOjUYYv+X0rg8SYxI99mE=
github.com/magiconair/properties v1.8.10/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/maki5/reva/v3 v3.0.0-20261117123005-56afac944faf h1:4cTvTHMbTxJf99AKyMms1JBesygi1yv7sxEknWZAnDE=
github.com/maki5/reva/v3 v3.0.0-20261117123005-56afac944faf/go.mod h1:GYVaPfxKgmER65YvpN0uwYL8QSXnwXbR4Qr3iwsYlPU=
github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo=
github.com/maruel/natural v1.1.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg=
github.com/mattermost/xml-roundtrip-validator v0.1.0 h1:RXbVD2UAl7A7nOTR4u7E3ILa4IbtvKBHw64LDsmu9hU=
@@ -763,8 +761,8 @@ github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89 h1:W1ms+l
github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89/go.mod h1:vigJkNss1N2QEceCuNw/ullDehncuJNFB6mEnzfq9UI=
github.com/opencloud-eu/libre-graph-api-go v1.0.9-0.20261119152805-1a7a500a264e h1:5sf3dNw/eYuuvDL8+3c4pbPSX+Pblw6lsylGtq+cw30=
github.com/opencloud-eu/libre-graph-api-go v1.0.9-0.20261119152805-1a7a500a264e/go.mod h1:lTM8JeGblNpoMySTW7Lui2+c5TTLI95mwxtdUIHHrhU=
github.com/opencloud-eu/reva/v3 v3.0.2-0.20261119154313-aa77b15bccec h1:3Y/o9uwiQ07c5Od1E/6TQQPDzN2uHeOACzW+d/+KGBQ=
github.com/opencloud-eu/reva/v3 v3.0.2-0.20261119154313-aa77b15bccec/go.mod h1:lwylaua29K7ge30pFxzHMh6LeH9bhCQduFdw+qKFzJA=
github.com/opencloud-eu/reva/v3 v3.0.2-0.20261120162312-20c6e78244d3 h1:lB4loaAtlU4J5OzZBcIOFDUozjRiltnMJZpqy9gonI0=
github.com/opencloud-eu/reva/v3 v3.0.2-0.20261120162312-20c6e78244d3/go.mod h1:oqi8rN/Nt2v+Gn/dmY9p2Zct3VHrdvnYtqZWHrjij7M=
github.com/opencloud-eu/secure v0.0.0-20260312082735-b6f5cb2244e4 h1:l2oB/RctH+t8r7QBj5p8thfEHCM/jF35aAY3WQ3hADI=
github.com/opencloud-eu/secure v0.0.0-20260312082735-b6f5cb2244e4/go.mod h1:BmF5hyM6tXczk3MpQkFf1hpKSRqCyhqcbiQtiAF7+40=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
+1 -6
View File
@@ -159,11 +159,6 @@ func New(o *options.Options, stream events.Stream, cache, historyCache *idcache.
var lu *lookup.Lookup
switch o.MetadataBackend {
case "xattrs":
lu, err = lookup.New(metadata.NewXattrsBackend(o.FileMetadataCache), um, o, &timemanager.Manager{}, cache, historyCache, log)
if err != nil {
return nil, err
}
case "hybrid":
lu, err = lookup.New(metadata.NewHybridBackend(1024, // start offloading grants after 1KB
func(n metadata.MetadataNode) string {
@@ -179,7 +174,7 @@ func New(o *options.Options, stream events.Stream, cache, historyCache *idcache.
return nil, err
}
default:
return nil, fmt.Errorf("unknown metadata backend %s, only 'xattrs' or 'hybrid' (default) supported", o.MetadataBackend)
return nil, fmt.Errorf("unknown metadata backend %s, only 'hybrid' (default) supported", o.MetadataBackend)
}
permissionsSelector, err := pool.PermissionsSelector(o.PermissionsSVC, pool.WithTLSMode(o.PermTLSMode))
@@ -140,6 +140,10 @@ func (fs *Decomposedfs) CommitUpload(ctx context.Context, ref *provider.Referenc
}
if revision == nil {
appctx.GetLogger(ctx).Info().Str("nodeid", n.ID).Str("sessionid", sessionID).Msg("upload was superseded and has no revision, discarding its bytes")
// a newer upload took over the node, nothing references the old blob anymore
if source.ObsoleteBlobID != sessionID {
fs.deleteObsoleteBlob(ctx, n, source.ObsoleteBlobID)
}
return nil
}
defer func() {
@@ -160,6 +164,12 @@ func (fs *Decomposedfs) CommitUpload(ctx context.Context, ref *provider.Referenc
return errors.Wrap(err, "Decomposedfs: failed to write blob")
}
// the node points to the new content now: the blob it pointed to before has no
// reference left
if source.ObsoleteBlobID != sessionID {
fs.deleteObsoleteBlob(ctx, n, source.ObsoleteBlobID)
}
// on the node that holds the content, not the session: the session is deleted when the
// upload finishes
if !source.ScanDate.IsZero() {
@@ -194,6 +204,19 @@ func (fs *Decomposedfs) CommitUpload(ctx context.Context, ref *provider.Referenc
return nil
}
// deleteObsoleteBlob deletes the blob an upload replaced, while the caller holds the node
// lock. It is kept if it is the one the node points to. A failure is only logged: the upload
// is done, and a leaked blob is better than a failed upload.
func (fs *Decomposedfs) deleteObsoleteBlob(ctx context.Context, n *node.Node, blobID string) {
if blobID == "" || blobID == n.BlobID {
return
}
blobNode := node.New(n.SpaceID, n.ID, "", "", 0, blobID, provider.ResourceType_RESOURCE_TYPE_FILE, nil, fs.lu)
if err := fs.tp.DeleteBlob(blobNode); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Str("blobid", blobID).Msg("could not delete the obsolete blob")
}
}
// removeRevisions deletes the revisions of n that were kept only for a rollback, with their
// blobs, while the caller holds the node lock: the ones of uploads that were rolled back,
// and the snapshots taken with versioning disabled.
@@ -78,6 +78,10 @@ const (
CtxKeySpaceGID CtxKey = iota
)
// maxDownloadAttempts is the number of times Download tries to open the blob of a node
// whose blob id changed in the meantime.
const maxDownloadAttempts = 3
var (
tracer trace.Tracer
@@ -136,12 +140,10 @@ func NewDefault(m map[string]interface{}, bs node.Blobstore, es events.Stream, l
var lu *lookup.Lookup
switch o.MetadataBackend {
case "xattrs":
lu = lookup.New(metadata.NewXattrsBackend(o.FileMetadataCache), o, &timemanager.Manager{})
case "messagepack":
lu = lookup.New(metadata.NewMessagePackBackend(o.FileMetadataCache), o, &timemanager.Manager{})
default:
return nil, fmt.Errorf("unknown metadata backend %s, only 'messagepack' or 'xattrs' (default) supported", o.MetadataBackend)
return nil, fmt.Errorf("unknown metadata backend %s, only 'messagepack' (default) supported", o.MetadataBackend)
}
permissionsSelector, err := pool.PermissionsSelector(o.PermissionsSVC, pool.WithTLSMode(o.PermTLSMode))
@@ -992,14 +994,54 @@ func (fs *Decomposedfs) Download(ctx context.Context, ref *provider.Reference, o
if err != nil {
return nil, nil, err
}
var reader io.ReadCloser
if openReaderFunc(ri) {
reader, err = fs.tp.ReadBlob(n)
if err != nil {
return nil, nil, errors.Wrap(err, "Decomposedfs: error download blob '"+n.ID+"'")
// A concurrent upload finalization can replace and delete the blob between resolving
// the node and opening the blob. If opening fails and the blob id of the node has
// changed, retry with the new blob.
log := appctx.GetLogger(ctx)
for attempt := 1; ; attempt++ {
reader, err := fs.tp.ReadBlob(n)
if err == nil {
return ri, reader, nil
}
err = errors.Wrap(err, "Decomposedfs: error download blob '"+n.ID+"'")
if attempt == maxDownloadAttempts {
return nil, nil, err
}
currentNode, readErr := node.ReadNode(ctx, fs.lu, n.SpaceID, n.ID, "", true, n.SpaceRoot, false)
if readErr != nil {
log.Warn().Err(readErr).AnErr("blobError", err).Str("nodeid", n.ID).Msg("could not re-read node after failing to open blob")
return nil, nil, err
}
if !currentNode.Exists {
return nil, nil, errtypes.NotFound(filepath.Join(n.ParentID, n.Name))
}
// a newer upload may have marked the node as processing, its blob is not written yet.
if currentNode.IsProcessing(ctx) {
return nil, nil, errtypes.TooEarly("file is still being processed")
}
if currentNode.BlobID != n.BlobID {
// the blob was replaced: retry with the new one
refreshed, riErr := currentNode.AsResourceInfo(ctx, rp, nil, []string{"size", "mimetype", "etag"}, true)
if riErr != nil {
log.Warn().Err(err).Str("nodeid", n.ID).Msg("dropped blob error, could not refresh resource info of replaced blob")
return nil, nil, riErr
}
log.Debug().
Err(err).
Str("nodeid", n.ID).
Str("oldblobid", n.BlobID).
Str("newblobid", currentNode.BlobID).
Int("attempt", attempt).
Msg("blob was replaced while opening it, retrying")
n, ri = currentNode, refreshed
continue
}
return nil, nil, err
}
}
return ri, reader, nil
return ri, nil, nil
}
// GetLock returns an existing lock on the given reference
@@ -357,7 +357,9 @@ func (lu *Lookup) TimeManager() node.TimeManager {
return lu.tm
}
// DetectBackendOnDisk returns the name of the metadata backend being used on disk
// DetectBackendOnDisk returns the name of the metadata backend being used on
// disk: "mpk" for messagepack, or "unknown" when the storage has no space with
// messagepack metadata, e.g. because root is wrong.
func DetectBackendOnDisk(root string) string {
matches, _ := filepath.Glob(filepath.Join(root, "spaces", "*", "*"))
if len(matches) > 0 {
@@ -370,10 +372,6 @@ func DetectBackendOnDisk(root string) string {
if err == nil {
return "mpk"
}
_, err = os.Stat(filepath.Join(base, "nodes", spaceRoot+".ini"))
if err == nil {
return "ini"
}
}
return "xattrs"
return "unknown"
}
@@ -1,354 +0,0 @@
// Copyright 2018-2023 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
package metadata
import (
"context"
"os"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/opencloud-eu/reva/v3/pkg/storage/cache"
"github.com/opencloud-eu/reva/v3/pkg/storage/pkg/decomposedfs/metadata/prefixes"
"github.com/opencloud-eu/reva/v3/pkg/storage/utils/filelocks"
"github.com/pkg/errors"
"github.com/pkg/xattr"
)
// XattrsBackend stores the file attributes in extended attributes
type XattrsBackend struct {
metaCache cache.FileMetadataCache
metrics *backendMetrics
}
// NewMessageBackend returns a new XattrsBackend instance
func NewXattrsBackend(o cache.Config) XattrsBackend {
return XattrsBackend{
metaCache: cache.GetFileMetadataCache(o),
metrics: newBackendMetrics("xattrs"),
}
}
// Name returns the name of the backend
func (XattrsBackend) Name() string { return "xattrs" }
// IdentifyPath returns the space id, node id and mtime of a file
func (b XattrsBackend) IdentifyPath(_ context.Context, path string) (string, string, string, time.Time, error) {
b.metrics.reads.Inc()
spaceID, _ := xattr.Get(path, prefixes.SpaceIDAttr)
id, _ := xattr.Get(path, prefixes.IDAttr)
parentID, _ := xattr.Get(path, prefixes.ParentidAttr)
mtimeAttr, _ := xattr.Get(path, prefixes.MTimeAttr)
mtime, _ := time.Parse(time.RFC3339Nano, string(mtimeAttr))
return string(spaceID), string(id), string(parentID), mtime, nil
}
// Get an extended attribute value for the given key
// No file locking is involved here as reading a single xattr is
// considered to be atomic.
func (b XattrsBackend) Get(ctx context.Context, n MetadataNode, key string) ([]byte, error) {
attribs := map[string][]byte{}
err := b.metaCache.PullFromCache(b.cacheKey(n), &attribs)
found := err == nil && len(attribs[key]) > 0
b.metrics.cacheLookup(found)
if found {
return attribs[key], err
}
b.metrics.reads.Inc()
return xattr.Get(n.InternalPath(), key)
}
// GetInt64 reads a string as int64 from the xattrs
func (b XattrsBackend) GetInt64(ctx context.Context, n MetadataNode, key string) (int64, error) {
attr, err := b.Get(ctx, n, key)
if err != nil {
return 0, err
}
v, err := strconv.ParseInt(string(attr), 10, 64)
if err != nil {
return 0, err
}
return v, nil
}
func (b XattrsBackend) list(ctx context.Context, n MetadataNode, acquireLock bool) (attribs []string, err error) {
filePath := n.InternalPath()
attrs, err := listXattr(ctx, filePath)
if err == nil {
return attrs, nil
}
// E2BIG means the attribute name list exceeds the maximum size the kernel
// returns (64KiB VFS limit, e.g. on XFS). It is not transient: fail fast
// instead of paying for the locked retry below.
if isTooBigError(err) {
return nil, err
}
// listing xattrs failed, try again, either with lock or without
if acquireLock {
lockPath := filePath + filelocks.LockFileSuffix
var f *heldLock
locked := true
if IsReadOnly(ctx) {
// lock only an existing lock file, and don't lock without one
f, locked, err = lockExisting(n, lockPath, os.O_WRONLY, b.metrics)
} else {
f, err = lockFile(n, lockPath, os.O_CREATE|os.O_WRONLY, b.metrics)
}
if err != nil {
return nil, err
}
if locked {
n.SetLockHeld(true)
// Warning: do not remove the lockfile or we may lock the same file more than once, https://github.com/opencloud-eu/opencloud/issues/1793
defer func() {
n.SetLockHeld(false)
_ = f.Close()
}()
}
}
return listXattr(ctx, filePath)
}
// All reads all extended attributes for a node. It acquires a shared file lock
// unless the caller already holds the node's metadata lock (n.LockHeld()).
func (b XattrsBackend) All(ctx context.Context, n MetadataNode) (map[string][]byte, error) {
return b.getAll(ctx, n, false, !n.LockHeld())
}
// Reload reads all extended attributes for a node from storage, never from the cache,
// and updates the cache with them. It acquires a shared file lock unless the caller
// already holds the node's metadata lock (n.LockHeld()).
func (b XattrsBackend) Reload(ctx context.Context, n MetadataNode) (map[string][]byte, error) {
attribs, err := b.getAll(ctx, n, true, !n.LockHeld())
if err != nil {
return nil, err
}
if len(attribs) == 0 {
// getAll doesn't cache a node without attributes, so the stale entry would stay
if err := b.metaCache.PushToCache(b.cacheKey(n), attribs); err != nil {
return nil, err
}
}
return attribs, nil
}
func (b XattrsBackend) getAll(ctx context.Context, n MetadataNode, skipCache, acquireLock bool) (map[string][]byte, error) {
attribs := map[string][]byte{}
if !skipCache {
err := b.metaCache.PullFromCache(b.cacheKey(n), &attribs)
b.metrics.cacheLookup(err == nil)
if err == nil {
return attribs, err
}
}
b.metrics.reads.Inc()
attrNames, err := b.list(ctx, n, acquireLock)
if err != nil {
return nil, err
}
if len(attrNames) == 0 {
return attribs, nil
}
var (
xerrs = 0
xerr error
)
// error handling: Count if there are errors while reading all attribs.
// if there were any, return an error.
attribs = make(map[string][]byte, len(attrNames))
path := n.InternalPath()
for _, name := range attrNames {
var val []byte
if val, xerr = xattr.Get(path, name); xerr != nil && !IsAttrUnset(xerr) {
xerrs++
} else {
attribs[name] = val
}
}
if xerrs > 0 {
return nil, errors.Wrap(xerr, "Failed to read all xattrs")
}
err = b.metaCache.PushToCache(b.cacheKey(n), attribs)
if err != nil {
return nil, err
}
return attribs, nil
}
// Set sets one attribute for the given path
func (b XattrsBackend) Set(ctx context.Context, n MetadataNode, key string, val []byte) (err error) {
return b.SetMultiple(ctx, n, map[string][]byte{key: val})
}
// SetMultiple sets a set of attribute for the given path
func (b XattrsBackend) SetMultiple(ctx context.Context, n MetadataNode, attribs map[string][]byte) (err error) {
path := n.InternalPath()
if !n.LockHeld() {
err := os.MkdirAll(filepath.Dir(path), 0700)
if err != nil {
return err
}
lockedFile, err := lockFile(n, b.LockfilePath(n), os.O_CREATE|os.O_WRONLY, b.metrics)
if err != nil {
return err
}
n.SetLockHeld(true)
// Warning: do not remove the lockfile or we may lock the same file more than once, https://github.com/opencloud-eu/opencloud/issues/1793
defer func() {
n.SetLockHeld(false)
_ = lockedFile.Close()
}()
}
// error handling: Count if there are errors while setting the attribs.
// if there were any, return an error.
var (
xerrs = 0
xerr error
)
b.metrics.writes.Inc()
for key, val := range attribs {
if xerr = xattr.Set(path, key, val); xerr != nil {
// log
xerrs++
}
}
if xerrs > 0 {
return errors.Wrap(xerr, "Failed to set all xattrs")
}
attribs, err = b.getAll(ctx, n, true, false)
if err != nil {
return err
}
return b.metaCache.PushToCache(b.cacheKey(n), attribs)
}
// Remove an extended attribute key
func (b XattrsBackend) Remove(ctx context.Context, n MetadataNode, key string) error {
path := n.InternalPath()
if !n.LockHeld() {
lockedFile, err := lockFile(n, path+filelocks.LockFileSuffix, os.O_CREATE|os.O_WRONLY, b.metrics)
if err != nil {
return err
}
n.SetLockHeld(true)
// Warning: do not remove the lockfile or we may lock the same file more than once, https://github.com/opencloud-eu/opencloud/issues/1793
defer func() {
n.SetLockHeld(false)
_ = lockedFile.Close()
}()
}
b.metrics.writes.Inc()
err := xattr.Remove(path, key)
if err != nil {
return err
}
attribs, err := b.getAll(ctx, n, true, false)
if err != nil {
return err
}
return b.metaCache.PushToCache(b.cacheKey(n), attribs)
}
// IsMetaFile returns whether the given path represents a meta file
func (XattrsBackend) IsMetaFile(path string) bool { return strings.HasSuffix(path, ".meta.lock") }
// Purge purges the data of a given path
func (b XattrsBackend) Purge(ctx context.Context, n MetadataNode) error {
path := n.InternalPath()
_, err := os.Stat(path)
if err == nil {
attribs, err := b.getAll(ctx, n, true, true)
if err != nil {
return err
}
b.metrics.writes.Inc()
for attr := range attribs {
if strings.HasPrefix(attr, prefixes.OcPrefix) {
err := xattr.Remove(path, attr)
if err != nil {
return err
}
}
}
}
return b.metaCache.RemoveMetadata(b.cacheKey(n))
}
// Rename moves the data for a given path to a new path
func (b XattrsBackend) Rename(oldNode, newNode MetadataNode) error {
data := map[string][]byte{}
err := b.metaCache.PullFromCache(b.cacheKey(oldNode), &data)
if err == nil {
err = b.metaCache.PushToCache(b.cacheKey(newNode), data)
if err != nil {
return err
}
}
return b.metaCache.RemoveMetadata(b.cacheKey(oldNode))
}
// MetadataPath returns the path of the file holding the metadata for the given path
func (XattrsBackend) MetadataPath(n MetadataNode) string { return n.InternalPath() }
// LockfilePath returns the path of the lock file
func (XattrsBackend) LockfilePath(n MetadataNode) string { return n.InternalPath() + ".mlock" }
// Lock locks the metadata for the given path
func (b XattrsBackend) Lock(n MetadataNode) (UnlockFunc, error) {
if n.LockHeld() {
return func() error { return nil }, nil
}
metaLockPath := b.LockfilePath(n)
mlock, err := lockFile(n, metaLockPath, os.O_RDWR|os.O_CREATE, b.metrics)
if err != nil {
return nil, err
}
n.SetLockHeld(true)
return func() error {
n.SetLockHeld(false)
// Warning: do not remove the lockfile or we may lock the same file more than once, https://github.com/opencloud-eu/opencloud/issues/1793
return mlock.Close()
}, nil
}
func (b XattrsBackend) cacheKey(n MetadataNode) string {
// rootPath is guaranteed to have no trailing slash
// the cache key shouldn't begin with a slash as some stores drop it which can cause
// confusion
return n.GetSpaceID() + "/" + n.GetID()
}
@@ -39,7 +39,7 @@ type Options struct {
// the gateway address
GatewayAddr string `mapstructure:"gateway_addr"`
// the metadata backend to use, currently supports `xattr` or `ini`
// the metadata backend to use, currently only supports 'messagepack' (default).
MetadataBackend string `mapstructure:"metadata_backend"`
// the attribute key prefix of the metadata on disk, process wide, see prefixes.SetOcPrefix
@@ -175,6 +175,7 @@ func (fs *Decomposedfs) PrepareUpload(ctx context.Context, ref *provider.Referen
versionNode *node.BaseNode
oldAttrs node.Attributes
oldMtime time.Time
obsoleteBlobID string
)
defer func() {
@@ -289,6 +290,13 @@ func (fs *Decomposedfs) PrepareUpload(ctx context.Context, ref *provider.Referen
}
}
// Without a revision the old blob has no reference left once the node points to
// the new one. A revision kept only for a rollback holds it until its removal.
// On posix the blob is the file itself, which the new content replaces.
if fs.o.DisableVersioning && fs.separateBlobs && overwrite && !versionCreated && old.BlobID != sessionID {
obsoleteBlobID = old.BlobID
}
sizeDiff = info.Size - old.Blobsize
} else {
// InitNewNode has cached a node it created
@@ -351,9 +359,13 @@ func (fs *Decomposedfs) PrepareUpload(ctx context.Context, ref *provider.Referen
// and their blobs are deleted with them.
n.BlobID = sessionID
fs.removeRevisions(ctx, n)
fs.deleteObsoleteBlob(ctx, n, obsoleteBlobID)
}
result := &storage.PrepareUploadResult{VersionCreated: versionCreated, SizeDiff: sizeDiff, Committed: inline}
if !inline {
result.ObsoleteBlobID = obsoleteBlobID
}
if !info.NodeExisted {
// read off the disk, not through ListGrants: an uploader who cannot see the
// space root still needs the manager of a project space reported
@@ -699,6 +699,13 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up
}, nil
}
spaceType, err := spaceNode.SpaceRoot.XattrString(ctx, prefixes.SpaceTypeAttr)
if err != nil {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_INTERNAL, Message: "space has no type"},
}, nil
}
sp, err := fs.p.AssemblePermissions(ctx, spaceNode)
if err != nil {
return &provider.UpdateStorageSpaceResponse{
@@ -723,17 +730,7 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up
}
if mapHasKey(metadata, k...) {
typ, err := spaceNode.SpaceRoot.Xattr(ctx, prefixes.SpaceTypeAttr)
if err != nil {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{
Code: v1beta11.Code_CODE_INTERNAL,
Message: "space has no type",
},
}, nil
}
if !fs.p.ManageSpaceProperties(ctx, spaceID, string(typ)) {
if !fs.p.ManageSpaceProperties(ctx, spaceID, spaceType) {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_PERMISSION_DENIED},
}, nil
@@ -741,17 +738,7 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up
}
if restore {
typ, err := spaceNode.SpaceRoot.XattrString(ctx, prefixes.SpaceTypeAttr)
if err != nil {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{
Code: v1beta11.Code_CODE_INTERNAL,
Message: "space has no type",
},
}, nil
}
if !fs.p.RestoreSpace(ctx, spaceID, typ) {
if !fs.p.RestoreSpace(ctx, spaceID, spaceType) {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_NOT_FOUND},
}, nil
@@ -760,17 +747,7 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up
}
if mapHasKey(metadata, prefixes.QuotaAttr) {
typ, err := spaceNode.SpaceRoot.Xattr(ctx, prefixes.SpaceTypeAttr)
if err != nil {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{
Code: v1beta11.Code_CODE_INTERNAL,
Message: "space has no type",
},
}, nil
}
if !fs.p.SetSpaceQuota(ctx, spaceID, string(typ)) {
if !fs.p.SetSpaceQuota(ctx, spaceID, spaceType) {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_PERMISSION_DENIED},
}, nil
+9
View File
@@ -73,6 +73,10 @@ type PrepareUploadResult struct {
// Committed reports that PrepareUpload stored UploadInfo.Source: the upload
// is complete, and neither CommitUpload nor MarkProcessing must follow.
Committed bool
// ObsoleteBlobID is the blob the node pointed to before this upload and
// that nothing else references. The driver deletes it once the new content
// is stored; the coordinator hands it back in UploadSource. Empty when none.
ObsoleteBlobID string
}
// RollbackInfo carries what a driver needs to undo PrepareUpload. NodeID and
@@ -275,6 +279,11 @@ type UploadSource struct {
// place instead of copying Body; the file is gone after a successful commit.
Path string
// ObsoleteBlobID is the blob the node pointed to before this upload and
// that nothing else references. The driver deletes it once the new content
// is stored. Empty when none.
ObsoleteBlobID string
// ScanResult is the antivirus verdict: empty means clean.
ScanResult string
// ScanDate is zero when the upload was not scanned.
+7 -5
View File
@@ -448,6 +448,7 @@ func (c *coordinator) prepare(ctx context.Context, session Session, info storage
}
session.SetSizeDiff(prepared.SizeDiff)
session.SetVersionCreated(prepared.VersionCreated)
session.SetObsoleteBlobID(prepared.ObsoleteBlobID)
if prepared.Committed {
// the upload is complete, the session is about to be removed
return true, nil
@@ -642,11 +643,12 @@ func (c *coordinator) commit(ctx context.Context, session Session) (*provider.Re
// CommitUpload does not own the body; we opened it, so we close it. The path
// lets a driver that can move the staged file into place skip the copy.
err = c.fs.CommitUpload(ctx, &ref, session.ID(), storage.UploadSource{
Body: f,
Path: session.BinPath(),
Length: session.Size(),
ScanResult: scanResult,
ScanDate: scanDate,
Body: f,
Path: session.BinPath(),
Length: session.Size(),
ObsoleteBlobID: session.ObsoleteBlobID(),
ScanResult: scanResult,
ScanDate: scanDate,
})
f.Close()
if err != nil {
+14
View File
@@ -83,6 +83,8 @@ type Session interface {
SetSizeDiff(d int64)
VersionCreated() bool
SetVersionCreated(v bool)
ObsoleteBlobID() string
SetObsoleteBlobID(id string)
Metadata() map[string]string
Persist(ctx context.Context) error
Cleanup(ctx context.Context, cleanBin, cleanInfo bool)
@@ -320,6 +322,18 @@ func (s *FileSession) SetVersionCreated(v bool) {
s.info.MetaData["versionCreated"] = strconv.FormatBool(v)
}
// ObsoleteBlobID returns the blob PrepareUpload reported as replaced by this
// upload, for the driver to delete once the new content is stored.
func (s *FileSession) ObsoleteBlobID() string {
return s.info.MetaData["obsoleteBlobID"]
}
// SetObsoleteBlobID records what PrepareUpload reported. Persisted for the same
// reason as the size diff: on the async path the commit runs in another process.
func (s *FileSession) SetObsoleteBlobID(id string) {
s.info.MetaData["obsoleteBlobID"] = id
}
// SetScanData stores AV scan results on the session.
func (s *FileSession) SetScanData(result string, date time.Time) {
s.info.MetaData["scanResult"] = result
+1 -2
View File
@@ -1360,7 +1360,7 @@ github.com/opencloud-eu/icap-client
# github.com/opencloud-eu/libre-graph-api-go v1.0.9-0.20261119152805-1a7a500a264e
## explicit; go 1.23
github.com/opencloud-eu/libre-graph-api-go
# github.com/opencloud-eu/reva/v3 v3.0.2-0.20261119154313-aa77b15bccec
# github.com/opencloud-eu/reva/v3 v3.0.2-0.20261120162312-20c6e78244d3
## explicit; go 1.26.0
github.com/opencloud-eu/reva/v3/cmd/revad/internal/grace
github.com/opencloud-eu/reva/v3/cmd/revad/runtime
@@ -2693,4 +2693,3 @@ stash.kopano.io/kgol/rndm
# github.com/unrolled/secure => github.com/opencloud-eu/secure v0.0.0-20260312082735-b6f5cb2244e4
# go-micro.dev/v4 => github.com/butonic/go-micro/v4 v4.11.4-0.20260929213538-cd412c159a26
# github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/opencloud-eu/go-micro-plugins/v4/store/nats-js-kv v0.0.0-20250512152754-23325793059a
# github.com/opencloud-eu/reva/v3 => github.com/maki5/reva/v3 v3.0.0-20261117123005-56afac944faf