Skip to content

Commit

Permalink
fix revision etag and size
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Nov 12, 2024
1 parent 3f06f52 commit 6de8f99
Showing 1 changed file with 11 additions and 57 deletions.
68 changes: 11 additions & 57 deletions pkg/storage/utils/decomposedfs/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/metadata/prefixes"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
)

// Revision entries are stored inside the node folder and start with the same uuid as the current version.
Expand Down Expand Up @@ -113,7 +114,7 @@ func (fs *Decomposedfs) ListRevisions(ctx context.Context, ref *provider.Referen

// DownloadRevision returns a reader for the specified revision
// FIXME the CS3 api should explicitly allow initiating revision and trash download, a related issue is https://github.com/cs3org/reva/issues/1813
func (fs *Decomposedfs) DownloadRevisionConsistent(ctx context.Context, ref *provider.Reference, revisionKey string) (*provider.ResourceInfo, func(ctx context.Context, ref *provider.Reference) (io.ReadCloser, error), error) {
func (fs *Decomposedfs) DownloadRevision(ctx context.Context, ref *provider.Reference, revisionKey string, openReaderFunc func(md *provider.ResourceInfo) bool) (*provider.ResourceInfo, io.ReadCloser, error) {
log := appctx.GetLogger(ctx)

// verify revision key format
Expand Down Expand Up @@ -151,73 +152,26 @@ func (fs *Decomposedfs) DownloadRevisionConsistent(ctx context.Context, ref *pro

blobid, blobsize, err := fs.lu.ReadBlobIDAndSizeAttr(ctx, contentPath, nil)
if err != nil {
return nil, nil, errors.Wrapf(err, "Decomposedfs: could not read blob id and size for revision '%s' of node '%s'", n.ID, revisionKey)
return nil, nil, errors.Wrapf(err, "Decomposedfs: could not read blob id and size for revision '%s' of node '%s'", kp[1], n.ID)
}

revisionNode := node.Node{SpaceID: spaceID, BlobID: blobid, Blobsize: blobsize} // blobsize is needed for the s3ng blobstore

md, err := revisionNode.AsResourceInfo(ctx, rp, []string{}, []string{}, true)
if err != nil {
return nil, nil, err
}
return md, func(ctx context.Context, ref *provider.Reference) (io.ReadCloser, error) {

reader, err := fs.tp.ReadBlob(&revisionNode)
if err != nil {
return nil, errors.Wrapf(err, "Decomposedfs: could not download blob of revision '%s' for node '%s'", n.ID, revisionKey)
}
return reader, nil
}, nil
}

// DownloadRevision returns a reader for the specified revision
// FIXME the CS3 api should explicitly allow initiating revision and trash download, a related issue is https://github.com/cs3org/reva/issues/1813
func (fs *Decomposedfs) DownloadRevision(ctx context.Context, ref *provider.Reference, revisionKey string, openReaderFunc func(md *provider.ResourceInfo) bool) (*provider.ResourceInfo, io.ReadCloser, error) {
log := appctx.GetLogger(ctx)

// verify revision key format
kp := strings.SplitN(revisionKey, node.RevisionIDDelimiter, 2)
if len(kp) != 2 {
log.Error().Str("revisionKey", revisionKey).Msg("malformed revisionKey")
return nil, nil, errtypes.NotFound(revisionKey)
}
log.Debug().Str("revisionKey", revisionKey).Msg("DownloadRevision")

spaceID := ref.ResourceId.SpaceId
// check if the node is available and has not been deleted
n, err := node.ReadNode(ctx, fs.lu, spaceID, kp[0], false, nil, false)
ri, err := n.AsResourceInfo(ctx, rp, nil, []string{"size", "mimetype", "etag"}, true)
if err != nil {
return nil, nil, err
}
if !n.Exists {
err = errtypes.NotFound(filepath.Join(n.ParentID, n.Name))
return nil, nil, err
}

rp, err := fs.p.AssemblePermissions(ctx, n)
switch {
case err != nil:
return nil, nil, err
case !rp.ListFileVersions || !rp.InitiateFileDownload: // TODO add explicit permission in the CS3 api?
f, _ := storagespace.FormatReference(ref)
if rp.Stat {
return nil, nil, errtypes.PermissionDenied(f)
}
return nil, nil, errtypes.NotFound(f)
}

contentPath := fs.lu.InternalPath(spaceID, revisionKey)

blobid, blobsize, err := fs.lu.ReadBlobIDAndSizeAttr(ctx, contentPath, nil)
// update resource info with revision data
mtime, err := time.Parse(time.RFC3339Nano, kp[1])
if err != nil {
return nil, nil, errors.Wrapf(err, "Decomposedfs: could not read blob id and size for revision '%s' of node '%s'", n.ID, revisionKey)
return nil, nil, errors.Wrapf(err, "Decomposedfs: could not parse mtime for revision '%s' of node '%s'", kp[1], n.ID)
}

revisionNode := node.Node{SpaceID: spaceID, BlobID: blobid, Blobsize: blobsize} // blobsize is needed for the s3ng blobstore

ri, err := n.AsResourceInfo(ctx, rp, nil, []string{"size", "mimetype", "etag"}, true)
ri.Size = uint64(blobsize)
ri.Mtime = utils.TimeToTS(mtime)
ri.Etag, err = node.CalculateEtag(n.ID, mtime)
if err != nil {
return nil, nil, err
return nil, nil, errors.Wrapf(err, "error calculating etag for revision '%s' of node '%s'", kp[1], n.ID)
}

var reader io.ReadCloser
Expand Down

0 comments on commit 6de8f99

Please sign in to comment.