Skip to content

Commit

Permalink
fix logic & logging
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic authored and David Christofas committed Jul 19, 2021
1 parent 07b6eb0 commit 477e24c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
11 changes: 5 additions & 6 deletions pkg/rhttp/datatx/utils/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,15 @@ func GetOrHeadFile(w http.ResponseWriter, r *http.Request, fs storage.FS, spaceI
// build a storage space reference
storageid, opaqeid, err := utils.SplitStorageSpaceID(spaceID)
if err != nil {
ref = &provider.Reference{
ResourceId: &provider.ResourceId{StorageId: storageid, OpaqueId: opaqeid},
// ensure the relative path starts with '.'
Path: utils.MakeRelativePath(fn),
}
} else {
sublog.Error().Str("space_id", spaceID).Str("path", fn).Msg("invalid reference")
w.WriteHeader(http.StatusBadRequest)
return
}
ref = &provider.Reference{
ResourceId: &provider.ResourceId{StorageId: storageid, OpaqueId: opaqeid},
// ensure the relative path starts with '.'
Path: utils.MakeRelativePath(fn),
}
}
// TODO check preconditions like If-Range, If-Match ...

Expand Down
24 changes: 20 additions & 4 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ package decomposedfs

import (
"context"
"fmt"
"io"
"math"
"net/url"
"os"
"path/filepath"
"strconv"
"strings"
"syscall"

userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
Expand Down Expand Up @@ -217,14 +217,14 @@ func (fs *Decomposedfs) CreateHome(ctx context.Context) (err error) {
}

// add storage space
if err := fs.createStorageSpace("personal", h.ID); err != nil {
if err := fs.createStorageSpace(ctx, "personal", h.ID); err != nil {
return err
}

return
}

func (fs *Decomposedfs) createStorageSpace(spaceType, nodeID string) error {
func (fs *Decomposedfs) createStorageSpace(ctx context.Context, spaceType, nodeID string) error {

// create space type dir
if err := os.MkdirAll(filepath.Join(fs.o.Root, "spaces", spaceType), 0700); err != nil {
Expand All @@ -234,12 +234,28 @@ func (fs *Decomposedfs) createStorageSpace(spaceType, nodeID string) error {
// we can reuse the node id as the space id
err := os.Symlink("../../nodes/"+nodeID, filepath.Join(fs.o.Root, "spaces", spaceType, nodeID))
if err != nil {
fmt.Printf("could not create symlink for '%s' space %s, %s\n", spaceType, nodeID, err)
if isAlreadyExists(err) {
appctx.GetLogger(ctx).Debug().Err(err).Str("node", nodeID).Str("spacetype", spaceType).Msg("symlink already exists")
} else {
// TODO how should we handle error cases here?
appctx.GetLogger(ctx).Error().Err(err).Str("node", nodeID).Str("spacetype", spaceType).Msg("could not create symlink")
}
}

return nil
}

// The os not exists error is buried inside the xattr error,
// so we cannot just use os.IsNotExists().
func isAlreadyExists(err error) bool {
if xerr, ok := err.(*os.LinkError); ok {
if serr, ok2 := xerr.Err.(syscall.Errno); ok2 {
return serr == syscall.EEXIST
}
}
return false
}

// GetHome is called to look up the home path for a user
// It is NOT supposed to return the internal path but the external path
func (fs *Decomposedfs) GetHome(ctx context.Context) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (fs *Decomposedfs) AddGrant(ctx context.Context, ref *provider.Reference, g
return err
}

if err := fs.createStorageSpace("share", node.ID); err != nil {
if err := fs.createStorageSpace(ctx, "share", node.ID); err != nil {
return err
}

Expand Down

0 comments on commit 477e24c

Please sign in to comment.