From 66e477992c0dc34fc610fc22edb86d358a270a29 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Wed, 9 Jun 2021 12:40:08 +0200 Subject: [PATCH] update the owncloudsql storage driver --- pkg/storage/fs/owncloudsql/owncloudsql.go | 52 +++++++++++------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/pkg/storage/fs/owncloudsql/owncloudsql.go b/pkg/storage/fs/owncloudsql/owncloudsql.go index 2b7b8713988..b5a8463bef6 100644 --- a/pkg/storage/fs/owncloudsql/owncloudsql.go +++ b/pkg/storage/fs/owncloudsql/owncloudsql.go @@ -585,7 +585,7 @@ func (fs *ocfs) convertToResourceInfo(ctx context.Context, fi os.FileInfo, ip st } ri := &provider.ResourceInfo{ - Id: &provider.ResourceId{OpaqueId: strconv.Itoa(cacheEntry.ID)}, + Id: &provider.Reference{NodeId: strconv.Itoa(cacheEntry.ID)}, Path: sp, Type: getResourceType(fi.IsDir()), Etag: cacheEntry.Etag, @@ -628,8 +628,8 @@ func getResourceType(isDir bool) provider.ResourceType { } // GetPathByID returns the storage relative path for the file id, without the internal namespace -func (fs *ocfs) GetPathByID(ctx context.Context, id *provider.ResourceId) (string, error) { - ip, err := fs.filecache.Path(id.OpaqueId) +func (fs *ocfs) GetPathByID(ctx context.Context, id *provider.Reference) (string, error) { + ip, err := fs.filecache.Path(id.NodeId) if err != nil { return "", err } @@ -655,25 +655,20 @@ func (fs *ocfs) resolve(ctx context.Context, ref *provider.Reference) (string, e return fs.toInternalPath(ctx, ref.GetPath()), nil } - if ref.GetId() != nil { - p, err := fs.filecache.Path(ref.GetId().OpaqueId) - if err != nil { - return "", err - } - p = strings.TrimPrefix(p, "files/") - if !fs.c.EnableHome { - u, ok := user.ContextGetUser(ctx) - if !ok { - return "", fmt.Errorf("could not infer user from context") - } - p = filepath.Join(u.Username, p) + p, err := fs.filecache.Path(ref.NodeId) + if err != nil { + return "", err + } + p = strings.TrimPrefix(p, "files/") + if !fs.c.EnableHome { + u, ok := user.ContextGetUser(ctx) + if !ok { + return "", fmt.Errorf("could not infer user from context") } - - return fs.toInternalPath(ctx, p), nil + p = filepath.Join(u.Username, p) } - // reference is invalid - return "", fmt.Errorf("invalid reference %+v", ref) + return fs.toInternalPath(ctx, p), nil } func (fs *ocfs) AddGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error { @@ -909,7 +904,7 @@ func (fs *ocfs) GetHome(ctx context.Context) (string, error) { return "", nil } -func (fs *ocfs) CreateDir(ctx context.Context, sp string) (err error) { +func (fs *ocfs) CreateDir(ctx context.Context, ref *provider.Reference, sp string) (err error) { ip := fs.toInternalPath(ctx, sp) // check permissions of parent dir @@ -1990,7 +1985,7 @@ func (fs *ocfs) convertToRecycleItem(ctx context.Context, md os.FileInfo) *provi Type: getResourceType(md.IsDir()), Key: md.Name(), // TODO do we need to prefix the path? it should be relative to this storage root, right? - Path: originalPath, + Ref: &provider.Reference{Path: originalPath}, Size: uint64(md.Size()), DeletionTime: &types.Timestamp{ Seconds: uint64(ttime), @@ -2026,7 +2021,7 @@ func (fs *ocfs) ListRecycle(ctx context.Context) ([]*provider.RecycleItem, error return items, nil } -func (fs *ocfs) RestoreRecycleItem(ctx context.Context, key, restorePath string) error { +func (fs *ocfs) RestoreRecycleItem(ctx context.Context, key string, restoreRef *provider.Reference) error { // TODO check permission? on what? user must be the owner? log := appctx.GetLogger(ctx) rp, err := fs.getRecyclePath(ctx) @@ -2041,17 +2036,17 @@ func (fs *ocfs) RestoreRecycleItem(ctx context.Context, key, restorePath string) return nil } - if restorePath == "" { + if restoreRef.Path == "" { v, err := xattr.Get(src, trashOriginPrefix) if err != nil { log.Error().Err(err).Str("key", key).Str("path", src).Msg("could not read origin") } - restorePath = filepath.Join("/", filepath.Clean(string(v)), strings.TrimSuffix(filepath.Base(src), suffix)) + restoreRef.Path = filepath.Join("/", filepath.Clean(string(v)), strings.TrimSuffix(filepath.Base(src), suffix)) } - tgt := fs.toInternalPath(ctx, restorePath) + tgt := fs.toInternalPath(ctx, restoreRef.Path) // move back to original location if err := os.Rename(src, tgt); err != nil { - log.Error().Err(err).Str("key", key).Str("restorePath", restorePath).Str("src", src).Str("tgt", tgt).Msg("could not restore item") + log.Error().Err(err).Str("key", key).Str("restorePath", restoreRef.Path).Str("src", src).Str("tgt", tgt).Msg("could not restore item") return errors.Wrap(err, "ocfs: could not restore item") } @@ -2159,6 +2154,11 @@ func (fs *ocfs) HashFile(path string) (string, string, string, error) { } } +func (fs *ocfs) ListStorageSpaces(ctx context.Context, filter []*provider.ListStorageSpacesRequest_Filter) ([]*provider.StorageSpace, error) { + //TODO(corby): Implement + return nil, nil +} + func readChecksumIntoResourceChecksum(ctx context.Context, checksums, algo string, ri *provider.ResourceInfo) { re := regexp.MustCompile(strings.ToUpper(algo) + `:(.*)`) matches := re.FindStringSubmatch(checksums)