From 5965a258f66b036bb819aa59a2d260452a2e7dd7 Mon Sep 17 00:00:00 2001 From: Dominic Della Valle Date: Fri, 10 Aug 2018 12:33:46 -0400 Subject: [PATCH] fix MFS resolve + misc License: MIT Signed-off-by: Dominic Della Valle --- mount/cgofuse/interface.go | 10 +++++++--- mount/cgofuse/read.go | 6 +++--- mount/cgofuse/utils.go | 9 +++++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/mount/cgofuse/interface.go b/mount/cgofuse/interface.go index 87663569d488..e160302b7528 100644 --- a/mount/cgofuse/interface.go +++ b/mount/cgofuse/interface.go @@ -4,6 +4,7 @@ import ( "context" "errors" logging "gx/ipfs/QmRREK2CAZ5Re2Bd9zZFG6FeYDppUWt5cMgsoUEp3ktgSr/go-log" + gopath "path" "strings" "time" @@ -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 } } @@ -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 } } @@ -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 @@ -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 { diff --git a/mount/cgofuse/read.go b/mount/cgofuse/read.go index bd72577fa498..2f4d1e49372a 100644 --- a/mount/cgofuse/read.go +++ b/mount/cgofuse/read.go @@ -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) @@ -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 } @@ -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") } diff --git a/mount/cgofuse/utils.go b/mount/cgofuse/utils.go index 0d51035bc141..9d3c326a5a94 100644 --- a/mount/cgofuse/utils.go +++ b/mount/cgofuse/utils.go @@ -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 @@ -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{} } @@ -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