Skip to content

Commit

Permalink
fix MFS resolve + misc
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Dominic Della Valle <[email protected]>
  • Loading branch information
djdv committed Aug 10, 2018
1 parent 57819ef commit 5965a25
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
10 changes: 7 additions & 3 deletions mount/cgofuse/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
logging "gx/ipfs/QmRREK2CAZ5Re2Bd9zZFG6FeYDppUWt5cMgsoUEp3ktgSr/go-log"
gopath "path"
"strings"
"time"

Expand Down Expand Up @@ -106,7 +107,7 @@ func (fn *ipnsNode) Resolve(path string) (string, error) {
keys, err = fn.core.Key().List(fn.ctx)
if err != nil {
log.Errorf("IPNS - Key err: %v", err)
return "", nil //TODO
return "", err
}
}

Expand All @@ -119,7 +120,7 @@ func (fn *ipnsNode) Resolve(path string) (string, error) {
for _, key := range keys {
if key.Name() == keyName {
log.Debugf("IPNS key %q found", keyName)
//FIXME: in the real world, we need to use a (stripped) key.Path()
//FIXME: in the real world, we need to use a key.Path(), not a pretty printer
return strings.Replace(path, keyName, key.ID().Pretty(), 1), nil
}
}
Expand All @@ -139,6 +140,7 @@ func (mfsNode) Mutable() bool {

//TODO: review
func (fn *mfsNode) Resolve(path string) (string, error) {
log.Debugf("MFSResolve - Request %q", path)
fsn, err := mfs.Lookup(fn.filesRoot, strings.TrimPrefix(path, "/local"))
if err != nil {
return "", err
Expand All @@ -148,7 +150,9 @@ func (fn *mfsNode) Resolve(path string) (string, error) {
if err != nil {
return "", err
}
return mfsNode.String(), nil

//TODO: check API, see if prefixed paths are ever returned; /ipns, ipld, etc.
return gopath.Join("/ipfs/", mfsNode.String()), nil
}

type fuseNode struct {
Expand Down
6 changes: 3 additions & 3 deletions mount/cgofuse/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ func (fs *FUSEIPFS) Readdir(path string,

return 0
}
//FIXME: needs typeswitch for resolvers / .Resolve

//subnodes
curNode, err := fs.pathFallback(path, fh)
if err != nil {
log.Errorf("Readdir - Path err {[%X]%q}:%v", fh, path, err)
Expand All @@ -325,7 +325,6 @@ func (fs *FUSEIPFS) Readdir(path string,

oLinks, err := fs.core.Object().Links(fs.ctx, curNode)
if err != nil {
log.Errorf("curNode: %q", curNode.String())
log.Errorf("Readdir - Link err {[%X]%q}:%v", fh, path, err)
return -fuse.ENOENT
}
Expand Down Expand Up @@ -412,7 +411,8 @@ func (fs *FUSEIPFS) pathFallback(path string, fh uint64) (fusePath, error) {
}

pc := strings.Split(path, "/")
if len(pc) < 3 {
if len(pc) < 2 {
log.Errorf("DBG - pf %q", path)
return nil, errors.New("path does not contain enough components to derive namespace")
}

Expand Down
9 changes: 7 additions & 2 deletions mount/cgofuse/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

//TODO: consider alternative methods for file handle management
// - using nil as an "in-use" marker
// - currently using nil as an "in-use" marker, not ideal
// - wrap around strategy is probably not ideal
// - do we need to handle timeouts here?
// - use of sync.Map may be useful
Expand Down Expand Up @@ -115,6 +115,11 @@ func (fs *FUSEIPFS) ipnsRootNodes() []fusePinPair {
curNode := key.Path()
pStat, err := fs.core.Object().Stat(fs.ctx, curNode)
if err != nil {
if err == coreiface.ErrOffline {
log.Error("ipnsRoot - Node if offline")
return []fusePinPair{}
//TODO: return []fusePinPair{fusePinPair{name: "Node is offline, can't resolve", stat: &fuse.Stat_t{Mode: fuse.S_IFREG | 0555}}}
}
log.Errorf("ipnsRoot - Stat err: %v", err)
return []fusePinPair{}
}
Expand Down Expand Up @@ -175,7 +180,7 @@ func (fs *FUSEIPFS) resolveMutable(fp fusePath) (fusePath, error) {
}
resolvedNode, err := fs.pathFallback(resolvedPath, invalidIndex)
if err != nil {
log.Errorf("resolveMutable - err %v", err)
log.Errorf("resolveMutable - %q err %v", fp.String(), err)
return nil, err
}
return resolvedNode, nil
Expand Down

0 comments on commit 5965a25

Please sign in to comment.