Skip to content

Commit

Permalink
introduce NodeInfo
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 committed Sep 1, 2020
1 parent c5337a6 commit 8f73e01
Show file tree
Hide file tree
Showing 7 changed files with 819 additions and 268 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ func init() {

type config struct {
MountPath string `mapstructure:"mount_path"`
MountID string `mapstructure:"mount_id"`
GatewayAddr string `mapstructure:"gateway_addr"`
}

type service struct {
conf *config
mountPath, mountID string
gateway gateway.GatewayAPIClient
conf *config
mountPath string
gateway gateway.GatewayAPIClient
}

func (s *service) Close() error {
Expand Down Expand Up @@ -85,7 +84,6 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {
}

mountPath := c.MountPath
mountID := c.MountID

gateway, err := pool.GetGatewayServiceClient(c.GatewayAddr)
if err != nil {
Expand All @@ -95,7 +93,6 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {
service := &service{
conf: c,
mountPath: mountPath,
mountID: mountID,
gateway: gateway,
}

Expand Down
58 changes: 58 additions & 0 deletions pkg/storage/fs/ocis/node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ocis

import (
"os"
"path/filepath"

"github.com/google/uuid"
"github.com/pkg/errors"
)

// NodeInfo allows referencing a node by id and optionally a relative path
type NodeInfo struct {
ParentID string
ID string
Name string
Exists bool
}

// BecomeParent rewrites the internal state to point to the parent id
func (n *NodeInfo) BecomeParent() {
n.ID = n.ParentID
n.ParentID = ""
n.Name = ""
n.Exists = false
}

// Create creates a new node in the given root and add symlinks to parent node
// TODO use a reference to the tree to access tho root?
func (n *NodeInfo) Create(root string) (err error) {

if n.ID != "" {
return errors.Wrap(err, "ocisfs: node already his an id")
}
// create a new file node
n.ID = uuid.New().String()

nodePath := filepath.Join(root, "nodes", n.ID)

err = os.MkdirAll(nodePath, 0700)
if err != nil {
return errors.Wrap(err, "ocisfs: could not create node dir")
}
// create back link
// we are not only linking back to the parent, but also to the filename
link := "../" + n.ParentID + "/children/" + n.Name
err = os.Symlink(link, filepath.Join(nodePath, "parentname"))
if err != nil {
return errors.Wrap(err, "ocisfs: could not symlink parent node")
}

// link child name to node
err = os.Symlink("../../"+n.ID, filepath.Join(root, "nodes", n.ParentID, "children", n.Name))
if err != nil {
return errors.Wrap(err, "ocisfs: could not symlink child entry")
}

return nil
}
Loading

0 comments on commit 8f73e01

Please sign in to comment.