diff --git a/changelog/unreleased/fix-recursive-trashcan-purge.md b/changelog/unreleased/fix-recursive-trashcan-purge.md new file mode 100644 index 00000000000..72289d775ad --- /dev/null +++ b/changelog/unreleased/fix-recursive-trashcan-purge.md @@ -0,0 +1,7 @@ +Bugfix: Bump reva to pull in changes to fix recursive trashcan purge + +We have fixed a bug in the trashcan purge process that did not delete folder structures recursively. + +https://github.com/owncloud/ocis/pull/8505 +https://github.com/owncloud/ocis/issues/8473 +https://github.com/cs3org/reva/pull/4533 diff --git a/go.mod b/go.mod index d6e12b33824..fb8a815094d 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/cenkalti/backoff v2.2.1+incompatible github.com/coreos/go-oidc/v3 v3.9.0 github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781 - github.com/cs3org/reva/v2 v2.18.1-0.20240221133359-3c387bebd755 + github.com/cs3org/reva/v2 v2.18.1-0.20240221153531-6d5a4d7e5c12 github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25 github.com/disintegration/imaging v1.6.2 github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e diff --git a/go.sum b/go.sum index 9d9a2d2e9b5..353491e6a63 100644 --- a/go.sum +++ b/go.sum @@ -1019,8 +1019,8 @@ github.com/crewjam/saml v0.4.14 h1:g9FBNx62osKusnFzs3QTN5L9CVA/Egfgm+stJShzw/c= github.com/crewjam/saml v0.4.14/go.mod h1:UVSZCf18jJkk6GpWNVqcyQJMD5HsRugBPf4I1nl2mME= github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781 h1:BUdwkIlf8IS2FasrrPg8gGPHQPOrQ18MS1Oew2tmGtY= github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva/v2 v2.18.1-0.20240221133359-3c387bebd755 h1:b0gZrGE6WKCdOwSOKX5wTzr3xPjGkreSSjOvllxKY7M= -github.com/cs3org/reva/v2 v2.18.1-0.20240221133359-3c387bebd755/go.mod h1:GRUrOp5HbFVwZTgR9bVrMZ/MvVy+Jhxw1PdMmhhKP9E= +github.com/cs3org/reva/v2 v2.18.1-0.20240221153531-6d5a4d7e5c12 h1:nm+0ee8PXEeYAFJvAcEUXLJob0muDh9FBPnEroi/IdQ= +github.com/cs3org/reva/v2 v2.18.1-0.20240221153531-6d5a4d7e5c12/go.mod h1:GRUrOp5HbFVwZTgR9bVrMZ/MvVy+Jhxw1PdMmhhKP9E= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/tree/tree.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/tree/tree.go index e6d108c0e91..6fc5176af31 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/tree/tree.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/tree/tree.go @@ -24,7 +24,6 @@ import ( "fmt" "io" "io/fs" - iofs "io/fs" "os" "path/filepath" "regexp" @@ -42,7 +41,6 @@ import ( "github.com/cs3org/reva/v2/pkg/utils" "github.com/google/uuid" "github.com/pkg/errors" - "github.com/rs/zerolog/log" "go-micro.dev/v4/store" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/trace" @@ -172,7 +170,7 @@ func (t *Tree) TouchFile(ctx context.Context, n *node.Node, markprocessing bool, return errors.Wrap(err, "Decomposedfs: could not remove symlink child entry") } } - if errors.Is(err, iofs.ErrNotExist) || link != "../"+n.ID { + if errors.Is(err, fs.ErrNotExist) || link != "../"+n.ID { relativeNodePath := filepath.Join("../../../../../", lookup.Pathify(n.ID, 4, 2)) if err = os.Symlink(relativeNodePath, childNameLink); err != nil { return errors.Wrap(err, "Decomposedfs: could not symlink child entry") @@ -529,6 +527,8 @@ func (t *Tree) Delete(ctx context.Context, n *node.Node) (err error) { // RestoreRecycleItemFunc returns a node and a function to restore it from the trash. func (t *Tree) RestoreRecycleItemFunc(ctx context.Context, spaceid, key, trashPath string, targetNode *node.Node) (*node.Node, *node.Node, func() error, error) { + logger := appctx.GetLogger(ctx) + recycleNode, trashItem, deletedNodePath, origin, err := t.readRecycleItem(ctx, spaceid, key, trashPath) if err != nil { return nil, nil, nil, err @@ -604,7 +604,7 @@ func (t *Tree) RestoreRecycleItemFunc(ctx context.Context, spaceid, key, trashPa deletePath = filepath.Join(resolvedTrashRoot, trashPath) } if err = os.Remove(deletePath); err != nil { - log.Error().Err(err).Str("trashItem", trashItem).Msg("error deleting trash item") + logger.Error().Err(err).Str("trashItem", trashItem).Msg("error deleting trash item") } var sizeDiff int64 @@ -624,13 +624,22 @@ func (t *Tree) RestoreRecycleItemFunc(ctx context.Context, spaceid, key, trashPa // PurgeRecycleItemFunc returns a node and a function to purge it from the trash func (t *Tree) PurgeRecycleItemFunc(ctx context.Context, spaceid, key string, path string) (*node.Node, func() error, error) { + logger := appctx.GetLogger(ctx) + rn, trashItem, deletedNodePath, _, err := t.readRecycleItem(ctx, spaceid, key, path) if err != nil { return nil, nil, err } + ts := "" + timeSuffix := strings.SplitN(filepath.Base(deletedNodePath), node.TrashIDDelimiter, 2) + if len(timeSuffix) == 2 { + ts = timeSuffix[1] + } + fn := func() error { - if err := t.removeNode(ctx, deletedNodePath, rn); err != nil { + + if err := t.removeNode(ctx, deletedNodePath, ts, rn); err != nil { return err } @@ -644,7 +653,7 @@ func (t *Tree) PurgeRecycleItemFunc(ctx context.Context, spaceid, key string, pa deletePath = filepath.Join(resolvedTrashRoot, path) } if err = os.Remove(deletePath); err != nil { - log.Error().Err(err).Str("deletePath", deletePath).Msg("error deleting trash item") + logger.Error().Err(err).Str("deletePath", deletePath).Msg("error deleting trash item") return err } @@ -654,22 +663,41 @@ func (t *Tree) PurgeRecycleItemFunc(ctx context.Context, spaceid, key string, pa return rn, fn, nil } -func (t *Tree) removeNode(ctx context.Context, path string, n *node.Node) error { +func (t *Tree) removeNode(ctx context.Context, path, timeSuffix string, n *node.Node) error { + logger := appctx.GetLogger(ctx) + + if timeSuffix != "" { + n.ID = n.ID + node.TrashIDDelimiter + timeSuffix + } + + if n.IsDir(ctx) { + item, err := t.ListFolder(ctx, n) + if err != nil { + logger.Error().Err(err).Str("path", path).Msg("error listing folder") + } else { + for _, child := range item { + if err := t.removeNode(ctx, child.InternalPath(), "", child); err != nil { + return err + } + } + } + } + // delete the actual node if err := utils.RemoveItem(path); err != nil { - log.Error().Err(err).Str("path", path).Msg("error purging node") + logger.Error().Err(err).Str("path", path).Msg("error purging node") return err } if err := t.lookup.MetadataBackend().Purge(path); err != nil { - log.Error().Err(err).Str("path", t.lookup.MetadataBackend().MetadataPath(path)).Msg("error purging node metadata") + logger.Error().Err(err).Str("path", t.lookup.MetadataBackend().MetadataPath(path)).Msg("error purging node metadata") return err } // delete blob from blobstore if n.BlobID != "" { if err := t.DeleteBlob(n); err != nil { - log.Error().Err(err).Str("blobID", n.BlobID).Msg("error purging nodes blob") + logger.Error().Err(err).Str("blobID", n.BlobID).Msg("error purging nodes blob") return err } } @@ -677,7 +705,7 @@ func (t *Tree) removeNode(ctx context.Context, path string, n *node.Node) error // delete revisions revs, err := filepath.Glob(n.InternalPath() + node.RevisionIDDelimiter + "*") if err != nil { - log.Error().Err(err).Str("path", n.InternalPath()+node.RevisionIDDelimiter+"*").Msg("glob failed badly") + logger.Error().Err(err).Str("path", n.InternalPath()+node.RevisionIDDelimiter+"*").Msg("glob failed badly") return err } for _, rev := range revs { @@ -687,18 +715,18 @@ func (t *Tree) removeNode(ctx context.Context, path string, n *node.Node) error bID, err := t.lookup.ReadBlobIDAttr(ctx, rev) if err != nil { - log.Error().Err(err).Str("revision", rev).Msg("error reading blobid attribute") + logger.Error().Err(err).Str("revision", rev).Msg("error reading blobid attribute") return err } if err := utils.RemoveItem(rev); err != nil { - log.Error().Err(err).Str("revision", rev).Msg("error removing revision node") + logger.Error().Err(err).Str("revision", rev).Msg("error removing revision node") return err } if bID != "" { if err := t.DeleteBlob(&node.Node{SpaceID: n.SpaceID, BlobID: bID}); err != nil { - log.Error().Err(err).Str("revision", rev).Str("blobID", bID).Msg("error removing revision node blob") + logger.Error().Err(err).Str("revision", rev).Str("blobID", bID).Msg("error removing revision node blob") return err } } @@ -761,6 +789,8 @@ var nodeIDRegep = regexp.MustCompile(`.*/nodes/([^.]*).*`) // TODO refactor the returned params into Node properties? would make all the path transformations go away... func (t *Tree) readRecycleItem(ctx context.Context, spaceID, key, path string) (recycleNode *node.Node, trashItem string, deletedNodePath string, origin string, err error) { + logger := appctx.GetLogger(ctx) + if key == "" { return nil, "", "", "", errtypes.InternalError("key is empty") } @@ -823,7 +853,7 @@ func (t *Tree) readRecycleItem(ctx context.Context, spaceID, key, path string) ( if attrBytes, err = backend.Get(ctx, resolvedTrashItem, prefixes.TrashOriginAttr); err == nil { origin = filepath.Join(string(attrBytes), path) } else { - log.Error().Err(err).Str("trashItem", trashItem).Str("deletedNodePath", deletedNodePath).Msg("could not read origin path, restoring to /") + logger.Error().Err(err).Str("trashItem", trashItem).Str("deletedNodePath", deletedNodePath).Msg("could not read origin path, restoring to /") } return diff --git a/vendor/modules.txt b/vendor/modules.txt index 0783179d21a..3760314d0c8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -359,7 +359,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.18.1-0.20240221133359-3c387bebd755 +# github.com/cs3org/reva/v2 v2.18.1-0.20240221153531-6d5a4d7e5c12 ## explicit; go 1.21 github.com/cs3org/reva/v2/cmd/revad/internal/grace github.com/cs3org/reva/v2/cmd/revad/runtime