Skip to content

Commit

Permalink
storage: execute layout template on oc storage (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
refs authored Mar 12, 2020
1 parent 3722005 commit 6d5875f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/separate/storage-home.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ enable_home_creation = true

[grpc.services.storageprovider.drivers.owncloud]
datadirectory = "/var/tmp/reva/data"
layout = "{{.UsernamePrefixCount.1}}/{{.UsernameLower}}"
layout = "{{.Username}}"

[grpc.services.storageprovider.path_wrappers.context]
prefix = ""
layout = "{{.UsernamePrefixCount.1}}/{{.UsernameLower}}"
layout = "{{.Username}}"

[http]
address = "0.0.0.0:12001"
Expand Down
31 changes: 26 additions & 5 deletions pkg/storage/fs/owncloud/owncloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/cs3org/reva/pkg/mime"
"github.com/cs3org/reva/pkg/storage"
"github.com/cs3org/reva/pkg/storage/fs/registry"
"github.com/cs3org/reva/pkg/storage/templates"
"github.com/cs3org/reva/pkg/user"
"github.com/gofrs/uuid"
"github.com/gomodule/redigo/redis"
Expand Down Expand Up @@ -845,12 +846,17 @@ func (fs *ocfs) GetQuota(ctx context.Context) (int, int, error) {
}

func (fs *ocfs) CreateHome(ctx context.Context) error {
home := fs.wrap(ctx, "/")
u, err := getUser(ctx)
if err != nil {
err = errors.Wrap(err, "oc CreateHome: no user in ctx and home is enabled")
panic(err)
}
layout := templates.WithUser(u, fs.c.Layout)

homePaths := []string{
path.Join(fs.c.DataDirectory, home, "files"),
path.Join(fs.c.DataDirectory, home, "files_trashbin"),
path.Join(fs.c.DataDirectory, home, "files_versions"),
path.Join(fs.c.DataDirectory, layout, "files"),
path.Join(fs.c.DataDirectory, layout, "files_trashbin"),
path.Join(fs.c.DataDirectory, layout, "files_versions"),
}

for _, v := range homePaths {
Expand All @@ -862,8 +868,23 @@ func (fs *ocfs) CreateHome(ctx context.Context) error {
return nil
}

func getUser(ctx context.Context) (*userpb.User, error) {
u, ok := user.ContextGetUser(ctx)
if !ok {
err := errors.Wrap(errtypes.UserRequired(""), "oc: error getting user from ctx")
return nil, err
}
return u, nil
}

func (fs *ocfs) GetHome(ctx context.Context) (string, error) {
home := fs.wrap(ctx, "/")
u, err := getUser(ctx)
if err != nil {
err = errors.Wrap(err, "oc GetHome: no user in ctx and home is enabled")
panic(err)
}
layout := templates.WithUser(u, fs.c.Layout)
home := path.Join(fs.c.DataDirectory, layout, "/")
return home, nil
}

Expand Down

0 comments on commit 6d5875f

Please sign in to comment.