Skip to content

Commit

Permalink
allow async postprocessing of files
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>

make postprocessing configurable

Signed-off-by: jkoberg <jkoberg@owncloud.com>

set node status only through node pkg

Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Jun 28, 2022
1 parent b8c78be commit 56440d5
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 684 deletions.
8 changes: 8 additions & 0 deletions internal/http/services/owncloud/ocdav/propfind/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,14 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
Propstat: []PropstatXML{},
}

if status := utils.ReadPlainFromOpaque(md.Opaque, "status"); status == "processing" {
response.Propstat = append(response.Propstat, PropstatXML{
Status: "HTTP/1.1 425 TOO EARLY", // TODO: use proper status code
Prop: []prop.PropertyXML{},
})
return &response, nil
}

var ls *link.PublicShare

// -1 indicates uncalculated
Expand Down
6 changes: 5 additions & 1 deletion pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,17 @@ func (fs *Decomposedfs) GetMD(ctx context.Context, ref *provider.Reference, mdKe
return
}

if !node.Exists {
isprocessed := node.IsProcessed()
if !isprocessed && !node.Exists {
err = errtypes.NotFound(filepath.Join(node.ParentID, node.Name))
return
}

rp, err := fs.p.AssemblePermissions(ctx, node)
switch {
case isprocessed:
// FIXME: how to check permissions for files while processing?
// the node is empty and holds no further information
case err != nil:
return nil, errtypes.InternalError(err.Error())
case !rp.Stat:
Expand Down
21 changes: 21 additions & 0 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,11 @@ func (n *Node) AsResourceInfo(ctx context.Context, rp *provider.ResourcePermissi
ParentId: parentID,
}

if n.IsProcessed() {
ri.Opaque = utils.AppendPlainToOpaque(ri.Opaque, "status", "processing")
return ri, nil
}

if nodeType == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
ts, err := n.GetTreeSize()
if err == nil {
Expand Down Expand Up @@ -1124,6 +1129,22 @@ func (n *Node) FindStorageSpaceRoot() error {
return nil
}

// MarkProcessing marks the node as being processed
func (n *Node) MarkProcessing() error {
return n.SetMetadata("user.ocis.nodestatus", "processing")
}

// UnmarkProcessing removes the processing flag from the node
func (n *Node) UnmarkProcessing() error {
return n.RemoveMetadata("user.ocis.nodestatus")
}

// IsProcessed returns true if the node is currently being processed
func (n *Node) IsProcessed() bool {
v, err := n.GetMetadata("user.ocis.nodestatus")
return err == nil && v == "processing"
}

// IsSpaceRoot checks if the node is a space root
func IsSpaceRoot(r *Node) bool {
path := r.InternalPath()
Expand Down
10 changes: 10 additions & 0 deletions pkg/storage/utils/decomposedfs/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package options
import (
"path/filepath"
"strings"
"time"

"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
Expand Down Expand Up @@ -51,6 +52,15 @@ type Options struct {

PersonalSpaceAliasTemplate string `mapstructure:"personalspacealias_template"`
GeneralSpaceAliasTemplate string `mapstructure:"generalspacealias_template"`

Postprocessing PostprocessingOptions `mapstructure:"postprocessing"`
}

// PostprocessingOptions defines the available options for postprocessing
type PostprocessingOptions struct {
ASyncFileUploads bool `mapstructure:"asyncfileuploads"`

DelayProcessing time.Duration `mapstructure:"delayprocessing"` // for testing purposes, or if you want to annoy your users
}

// New returns a new Options instance for the given configuration
Expand Down
Loading

0 comments on commit 56440d5

Please sign in to comment.