Skip to content

Commit 5965a25

Browse files
committed
fix MFS resolve + misc
License: MIT Signed-off-by: Dominic Della Valle <[email protected]>
1 parent 57819ef commit 5965a25

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

mount/cgofuse/interface.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
logging "gx/ipfs/QmRREK2CAZ5Re2Bd9zZFG6FeYDppUWt5cMgsoUEp3ktgSr/go-log"
7+
gopath "path"
78
"strings"
89
"time"
910

@@ -106,7 +107,7 @@ func (fn *ipnsNode) Resolve(path string) (string, error) {
106107
keys, err = fn.core.Key().List(fn.ctx)
107108
if err != nil {
108109
log.Errorf("IPNS - Key err: %v", err)
109-
return "", nil //TODO
110+
return "", err
110111
}
111112
}
112113

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

140141
//TODO: review
141142
func (fn *mfsNode) Resolve(path string) (string, error) {
143+
log.Debugf("MFSResolve - Request %q", path)
142144
fsn, err := mfs.Lookup(fn.filesRoot, strings.TrimPrefix(path, "/local"))
143145
if err != nil {
144146
return "", err
@@ -148,7 +150,9 @@ func (fn *mfsNode) Resolve(path string) (string, error) {
148150
if err != nil {
149151
return "", err
150152
}
151-
return mfsNode.String(), nil
153+
154+
//TODO: check API, see if prefixed paths are ever returned; /ipns, ipld, etc.
155+
return gopath.Join("/ipfs/", mfsNode.String()), nil
152156
}
153157

154158
type fuseNode struct {

mount/cgofuse/read.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ func (fs *FUSEIPFS) Readdir(path string,
309309

310310
return 0
311311
}
312-
//FIXME: needs typeswitch for resolvers / .Resolve
313312

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

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

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

mount/cgofuse/utils.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

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

0 commit comments

Comments
 (0)