Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if symlink exists instead of spamming the console #1992

Merged
merged 1 commit into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/remove-prints-for-spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Check if symlink exists instead of spamming the console

The logs have been spammed with messages like `could not create symlink for ...` when using the decomposedfs, eg. with the oCIS storage. We now check if the link exists before trying to create it.

https://github.com/cs3org/reva/pull/1992
58 changes: 46 additions & 12 deletions pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/cs3org/reva/pkg/appctx"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/logger"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/xattrs"
"github.com/cs3org/reva/pkg/utils"
Expand All @@ -44,6 +45,11 @@ import (

// go:generate mockery -name Blobstore

const (
spaceTypePersonal = "personal"
spaceTypeShare = "share"
)

// Blobstore defines an interface for storing blobs in a blobstore
type Blobstore interface {
Upload(key string, reader io.Reader) error
Expand Down Expand Up @@ -123,11 +129,11 @@ func (t *Tree) Setup(owner string) error {
fi, err := os.Stat(spacesPath)
if os.IsNotExist(err) {
// create personal spaces dir
if err := os.MkdirAll(filepath.Join(spacesPath, "personal"), 0700); err != nil {
if err := os.MkdirAll(filepath.Join(spacesPath, spaceTypePersonal), 0700); err != nil {
return err
}
// create share spaces dir
if err := os.MkdirAll(filepath.Join(spacesPath, "share"), 0700); err != nil {
if err := os.MkdirAll(filepath.Join(spacesPath, spaceTypeShare), 0700); err != nil {
return err
}

Expand All @@ -145,20 +151,14 @@ func (t *Tree) Setup(owner string) error {

// is it a user root? -> create personal space
if isRootNode(nodePath) {
// create personal space
// we can reuse the node id as the space id
err = os.Symlink("../../nodes/"+nodes[i].Name(), filepath.Join(t.root, "spaces/personal", nodes[i].Name()))
if err != nil {
fmt.Printf("could not create symlink for personal space %s, %s\n", nodes[i].Name(), err)
}
t.linkSpace(spaceTypePersonal, nodes[i].Name(), nodes[i].Name())
}

// is it a shared node? -> create shared space
// is it a shared node? -> create share space
if isSharedNode(nodePath) {
err = os.Symlink("../../nodes/"+nodes[i].Name(), filepath.Join(t.root, "spaces/share", nodes[i].Name()))
if err != nil {
fmt.Printf("could not create symlink for shared space %s, %s\n", nodes[i].Name(), err)
}
// we can reuse the node id as the space id
t.linkSpace(spaceTypeShare, nodes[i].Name(), nodes[i].Name())
}
}
} else if !fi.IsDir() {
Expand All @@ -169,6 +169,40 @@ func (t *Tree) Setup(owner string) error {
return nil
}

// linkSpace creates a new symbolic link for a space with the given type st, and node id
func (t *Tree) linkSpace(spaceType, spaceID, nodeID string) {
spacesPath := filepath.Join(t.root, "spaces", spaceType, spaceID)
expectedTarget := "../../nodes/" + nodeID
linkTarget, err := os.Readlink(spacesPath)
if errors.Is(err, os.ErrNotExist) {
err = os.Symlink(expectedTarget, spacesPath)
if err != nil {
logger.New().Error().Err(err).
Str("space_type", spaceType).
Str("space", spaceID).
Str("node", nodeID).
Msg("could not create symlink")
}
} else {
if err != nil {
logger.New().Error().Err(err).
Str("space_type", spaceType).
Str("space", spaceID).
Str("node", nodeID).
Msg("could not read symlink")
}
if linkTarget != expectedTarget {
logger.New().Warn().
Str("space_type", spaceType).
Str("space", spaceID).
Str("node", nodeID).
Str("expected", expectedTarget).
Str("actual", linkTarget).
Msg("expected a different link target")
}
}
}

func isRootNode(nodePath string) bool {
attrBytes, err := xattr.Get(nodePath, xattrs.ParentidAttr)
return err == nil && string(attrBytes) == "root"
Expand Down