Compare commits

...
Author SHA1 Message Date
Firas Frikha c29cddcca0 chore: bump reva for the OCM upload coordinator work 2026-08-07 12:17:26 +02:00
6 changed files with 144 additions and 24 deletions

No files matched your search

+1 -1
View File
@@ -67,7 +67,7 @@ require (
github.com/open-policy-agent/opa v1.19.0
github.com/orcaman/concurrent-map v1.0.0
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
github.com/owncloud/reva/v2 v2.0.0-20260806084131-831afd01e5d4
github.com/owncloud/reva/v2 v2.0.0-20260807095944-8056f5e1297e
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.12
github.com/prometheus/client_golang v1.24.1
+2 -2
View File
@@ -736,8 +736,8 @@ github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HD
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 h1:JRidLTAKhnvyLMRtVtSF4lhBa0NSAOs6fof+d6JnKII=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245/go.mod h1:z61VMGAJRtR1nbgXWiNoCkxUXP1B3Je9rMuJbnGd+Og=
github.com/owncloud/reva/v2 v2.0.0-20260806084131-831afd01e5d4 h1:Cnq24qhteHD30DfTG8o0bf3cnVL/2b+afz//0qGjAeU=
github.com/owncloud/reva/v2 v2.0.0-20260806084131-831afd01e5d4/go.mod h1:XBnHPPDOGYq+Uf/PD1wGXne3xTvoghBxXPUULcSZjlc=
github.com/owncloud/reva/v2 v2.0.0-20260807095944-8056f5e1297e h1:VyezYtf9tz6COz9sIk2i2szESueBPTI79KEOSR8I8Ug=
github.com/owncloud/reva/v2 v2.0.0-20260807095944-8056f5e1297e/go.mod h1:XBnHPPDOGYq+Uf/PD1wGXne3xTvoghBxXPUULcSZjlc=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pablodz/inotifywaitgo v0.0.12 h1:DVJJTFMDlSAdO46yisPF2vzozs/r+4k6ih8MVghq78M=
+57 -5
View File
@@ -253,7 +253,7 @@ func (d *driver) CreateDir(ctx context.Context, ref *provider.Reference) (*stora
}
func (d *driver) Delete(ctx context.Context, ref *provider.Reference) (*storage.DeleteResult, error) {
client, _, rel, err := d.webdavClient(ctx, nil, ref)
client, _, rel, err := d.serviceWebdavClient(ctx, ref)
if err != nil {
return nil, err
}
@@ -264,14 +264,24 @@ func (d *driver) Delete(ctx context.Context, ref *provider.Reference) (*storage.
}
func (d *driver) TouchFile(ctx context.Context, ref *provider.Reference, markprocessing bool, mtime string) (*storage.TouchFileResult, error) {
client, _, rel, err := d.webdavClient(ctx, nil, ref)
client, _, rel, err := d.serviceWebdavClient(ctx, ref)
if err != nil {
return nil, err
}
if err := client.Write(rel, []byte{}, 0); err != nil {
return nil, err
}
return &storage.TouchFileResult{}, nil
// callers address the touched file by the ids returned here, so encode them the
// same way a stat does (convertStatToResourceInfo)
shareID, _ := shareInfoFromReference(ref)
return &storage.TouchFileResult{
SpaceID: shareID.GetOpaqueId(),
ResourceID: &provider.ResourceId{
StorageId: utils.OCMStorageProviderID,
SpaceId: shareID.GetOpaqueId(),
OpaqueId: base64.StdEncoding.EncodeToString([]byte(filepath.Join("/", rel))),
},
}, nil
}
func (d *driver) Move(ctx context.Context, oldRef, newRef *provider.Reference) (*storage.MoveResult, error) {
@@ -347,6 +357,36 @@ func convertStatToResourceInfo(ref *provider.Reference, f fs.FileInfo, share *oc
return &ri, nil
}
// extractLock returns the active lock, or nil if there is none. Props.GetString
// renders a missing key as "<nil>", so require a parseable activelock with a token.
func extractLock(props gowebdav.Props) *provider.Lock {
raw := props.GetString(xml.Name{Space: "DAV:", Local: "lockdiscovery"})
// local names only: raw is innerxml, so the d: prefix is unbound and
// namespaced tags ("DAV: lockscope") would match nothing.
var al struct {
LockScope struct {
Exclusive *struct{} `xml:"exclusive"`
Shared *struct{} `xml:"shared"`
} `xml:"lockscope"`
LockToken struct {
Href string `xml:"href"`
} `xml:"locktoken"`
}
if err := xml.Unmarshal([]byte(raw), &al); err != nil {
return nil
}
if al.LockToken.Href == "" {
return nil
}
lockType := provider.LockType_LOCK_TYPE_EXCL
if al.LockScope.Shared != nil && al.LockScope.Exclusive == nil {
lockType = provider.LockType_LOCK_TYPE_SHARED
}
return &provider.Lock{LockId: al.LockToken.Href, Type: lockType}
}
func extractChecksum(props gowebdav.Props) *provider.ResourceChecksum {
checksums := props.GetString(xml.Name{Space: "http://owncloud.org/ns", Local: "checksums"})
if checksums == "" {
@@ -534,12 +574,24 @@ func (d *driver) GetLock(ctx context.Context, ref *provider.Reference) (*provide
return nil, err
}
token, err := client.GetLock(rel)
// gowebdav's GetLock stats with a fixed property set that omits lockdiscovery.
// getetag keeps the 200 propstat non-empty — unlocked resources report
// lockdiscovery in a 404 propstat, which gowebdav discards.
info, err := client.StatWithProps(rel, []string{"lockdiscovery", "getetag"})
if err != nil {
return nil, err
}
return &provider.Lock{LockId: token, Type: provider.LockType_LOCK_TYPE_EXCL}, nil
props, ok := info.Sys().(gowebdav.Props)
if !ok {
return nil, errtypes.InternalError("ocm: unexpected stat result for " + ref.GetPath())
}
lock := extractLock(props)
if lock == nil {
return nil, errtypes.NotFound("no lock found")
}
return lock, nil
}
func (d *driver) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock, existingLockID string) error {
+44 -3
View File
@@ -35,9 +35,11 @@ import (
"strings"
"github.com/google/uuid"
"github.com/studio-b12/gowebdav"
tusd "github.com/tus/tusd/v2/pkg/handler"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
ocmpb "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/owncloud/reva/v2/pkg/appctx"
ctxpkg "github.com/owncloud/reva/v2/pkg/ctx"
@@ -76,12 +78,51 @@ func (d *driver) InitiateUpload(ctx context.Context, ref *provider.Reference, up
}, nil
}
// MarkProcessing is a no-op: the file lives on the remote instance, so there is no
// local node to flag while postprocessing runs.
func (d *driver) MarkProcessing(ctx context.Context, ref *provider.Reference, processing bool, sessionID string) error {
return errtypes.NotSupported("op not supported")
return nil
}
func (d *driver) CommitUpload(_ context.Context, _ *provider.Reference, _ string, _ storage.UploadSource) error {
return errtypes.NotSupported("op not supported")
// CommitUpload streams the staged bytes to the remote instance.
func (d *driver) CommitUpload(ctx context.Context, ref *provider.Reference, sessionID string, source storage.UploadSource) error {
client, _, rel, err := d.serviceWebdavClient(ctx, ref)
if err != nil {
return err
}
client.SetInterceptor(func(method string, rq *http.Request) {
// Set the content length on the request struct directly instead of the header.
// The content-length header gets reset by the golang http library before
// sending out the request, resulting in chunked encoding to be used which
// breaks the quota checks in ocdav.
if method == "PUT" {
rq.ContentLength = source.Length
}
})
// the coordinator owns source.Body and closes it after this returns
lockToken, _ := ctxpkg.ContextGetLockID(ctx)
return client.WriteStream(rel, source.Body, 0, lockToken)
}
// serviceWebdavClient builds a webdav client without needing a request auth token:
// it authenticates as the service account and looks up the share on behalf of the
// upload's executant.
func (d *driver) serviceWebdavClient(ctx context.Context, ref *provider.Reference) (*gowebdav.Client, *ocmpb.ReceivedShare, string, error) {
gwc, err := d.gateway.Next()
if err != nil {
return nil, nil, "", err
}
serviceUserCtx, err := utils.GetServiceUserContext(d.c.ServiceAccountID, gwc, d.c.ServiceAccountSecret)
if err != nil {
return nil, nil, "", err
}
executant, ok := ctxpkg.ContextGetUser(ctx)
if !ok {
return nil, nil, "", errtypes.BadRequest("ocm: no executant in context")
}
return d.webdavClient(serviceUserCtx, executant.GetId(), ref)
}
func (d *driver) Upload(ctx context.Context, req storage.UploadRequest, _ storage.UploadFinishedFunc) (*provider.ResourceInfo, error) {
+39 -12
View File
@@ -413,6 +413,13 @@ func (fs *Decomposedfs) CommitUpload(ctx context.Context, ref *provider.Referenc
return errors.Wrap(err, "Decomposedfs: failed to write blob")
}
// on the node, not the session: the session is deleted when the upload finishes
if !source.ScanDate.IsZero() {
if err := n.SetScanData(ctx, source.ScanResult, source.ScanDate); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Msg("could not set scan results")
}
}
now := time.Now()
if p, err := n.Parent(ctx); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Msg("could not read parent for etag propagation")
@@ -491,24 +498,38 @@ func (fs *Decomposedfs) PrepareUpload(ctx context.Context, ref *provider.Referen
}
}
if info.NodeExisted && oldAttrs != nil {
// mtime goes in the same batch: we still hold the metadata lock and
// SetMTime would deadlock trying to retake it
if err := fs.lu.TimeManager().OverrideMtime(ctx, n, &oldAttrs, oldMtime); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Msg("could not restore node mtime during rollback")
}
if err := n.SetXattrsWithContext(ctx, oldAttrs, false); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Msg("could not restore node xattrs during rollback")
}
if err := fs.lu.TimeManager().SetMTime(ctx, n, &oldMtime); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Str("nodeid", n.ID).Msg("could not restore node mtime during rollback")
}
}
}()
var (
old *node.Node
overwrite bool
oldBlobsize int64
)
if info.NodeExisted {
old, err := node.ReadNode(ctx, fs.lu, n.SpaceID, n.ID, false, nil, false)
old, err = node.ReadNode(ctx, fs.lu, n.SpaceID, n.ID, false, nil, false)
if err != nil {
return nil, errors.Wrap(err, "PrepareUpload: failed to read existing node")
}
if _, err := node.CheckQuota(ctx, n.SpaceRoot, old.BlobID != "", uint64(old.Blobsize), uint64(info.Size)); err != nil {
return nil, err
}
overwrite = old.BlobID != ""
oldBlobsize = old.Blobsize
}
// also for new files: the coordinator's check fails open without GetQuota
// permission, and CheckQuota guards disk space too
if _, err := node.CheckQuota(ctx, n.SpaceRoot, overwrite, uint64(oldBlobsize), uint64(info.Size)); err != nil {
return nil, err
}
if info.NodeExisted {
oldMtime, err = old.GetMTime(ctx)
if err != nil {
return nil, err
@@ -633,7 +654,7 @@ func (fs *Decomposedfs) RollbackUpload(ctx context.Context, ref *provider.Refere
return fmt.Errorf("RollbackUpload: node lookup failed: %w", err)
}
if !n.Exists {
return nil // new node; coordinator calls Delete separately
return nil // nothing was written yet
}
n.SpaceRoot, err = node.ReadNode(ctx, fs.lu, n.SpaceID, n.SpaceID, false, nil, false)
if err != nil {
@@ -652,13 +673,19 @@ func (fs *Decomposedfs) RollbackUpload(ctx context.Context, ref *provider.Refere
if err := n.RevertCurrentRevision(ctx, false); err != nil {
return err
}
if sizeDiff != 0 {
if err := fs.tp.Propagate(ctx, n, -sizeDiff); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Msg("RollbackUpload: could not revert propagate")
}
} else {
// the upload created this node, so undo it. Purge, not trash: the file never
// became visible, and Purge needs no Delete permission
if err := n.Purge(ctx); err != nil {
return fmt.Errorf("RollbackUpload: could not purge node: %w", err)
}
}
if sizeDiff != 0 {
if err := fs.tp.Propagate(ctx, n, -sizeDiff); err != nil {
appctx.GetLogger(ctx).Error().Err(err).Msg("RollbackUpload: could not revert propagate")
}
}
return nil
}
+1 -1
View File
@@ -1323,7 +1323,7 @@ github.com/orcaman/concurrent-map
# github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
## explicit; go 1.18
github.com/owncloud/libre-graph-api-go
# github.com/owncloud/reva/v2 v2.0.0-20260806084131-831afd01e5d4
# github.com/owncloud/reva/v2 v2.0.0-20260807095944-8056f5e1297e
## explicit; go 1.26
github.com/owncloud/reva/v2/cmd/revad/internal/grace
github.com/owncloud/reva/v2/cmd/revad/runtime