Skip to content

Commit 8bdbcbf

Browse files
committed
fix(fuse): ipns error handling and friendly errors (#10807)
* fix(fusei/ux): check if paths exist, print err * fix(fuse): ipns 'could not resolve' error type changed when code got extracted to boxo, but it was not caught because of FUSE tests do not cover IPNS in online mode Closes #8095 Closes #2167 Closes #3013 * docs: clarify opt-in (cherry picked from commit f84fb28)
1 parent 36b28a0 commit 8bdbcbf

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

cmd/ipfs/kubo/daemon.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,16 +1065,25 @@ func mountFuse(req *cmds.Request, cctx *oldcmds.Context) error {
10651065
if !found {
10661066
fsdir = cfg.Mounts.IPFS
10671067
}
1068+
if err := checkFusePath("Mounts.IPFS", fsdir); err != nil {
1069+
return err
1070+
}
10681071

10691072
nsdir, found := req.Options[ipnsMountKwd].(string)
10701073
if !found {
10711074
nsdir = cfg.Mounts.IPNS
10721075
}
1076+
if err := checkFusePath("Mounts.IPNS", nsdir); err != nil {
1077+
return err
1078+
}
10731079

10741080
mfsdir, found := req.Options[mfsMountKwd].(string)
10751081
if !found {
10761082
mfsdir = cfg.Mounts.MFS
10771083
}
1084+
if err := checkFusePath("Mounts.MFS", mfsdir); err != nil {
1085+
return err
1086+
}
10781087

10791088
node, err := cctx.ConstructNode()
10801089
if err != nil {
@@ -1091,6 +1100,26 @@ func mountFuse(req *cmds.Request, cctx *oldcmds.Context) error {
10911100
return nil
10921101
}
10931102

1103+
func checkFusePath(name, path string) error {
1104+
if path == "" {
1105+
return fmt.Errorf("%s path cannot be empty", name)
1106+
}
1107+
1108+
fileInfo, err := os.Stat(path)
1109+
if err != nil {
1110+
if os.IsNotExist(err) {
1111+
return fmt.Errorf("%s path (%q) does not exist: %w", name, path, err)
1112+
}
1113+
return fmt.Errorf("error while inspecting %s path (%q): %w", name, path, err)
1114+
}
1115+
1116+
if !fileInfo.IsDir() {
1117+
return fmt.Errorf("%s path (%q) is not a directory", name, path)
1118+
}
1119+
1120+
return nil
1121+
}
1122+
10941123
func maybeRunGC(req *cmds.Request, node *core.IpfsNode) (<-chan error, error) {
10951124
enableGC, _ := req.Options[enableGCKwd].(bool)
10961125
if !enableGC {

docs/config.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,10 @@ Default: `cache`
13731373
## `Mounts`
13741374

13751375
> [!CAUTION]
1376-
> **EXPERIMENTAL:** read about current limitations at [fuse.md](./fuse.md).
1376+
> **EXPERIMENTAL:**
1377+
> This feature is disabled by default, requires an explicit opt-in with `ipfs mount` or `ipfs daemon --mount`.
1378+
>
1379+
> Read about current limitations at [fuse.md](./fuse.md).
13771380
13781381
FUSE mount point configuration options.
13791382

fuse/ipns/ipns_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
dag "github.com/ipfs/boxo/ipld/merkledag"
1818
ft "github.com/ipfs/boxo/ipld/unixfs"
19+
"github.com/ipfs/boxo/namesys"
1920
"github.com/ipfs/boxo/path"
2021

2122
fuse "bazil.org/fuse"
@@ -95,7 +96,7 @@ func loadRoot(ctx context.Context, ipfs iface.CoreAPI, key iface.Key) (*mfs.Root
9596
node, err := ipfs.ResolveNode(ctx, key.Path())
9697
switch err {
9798
case nil:
98-
case iface.ErrResolveFailed:
99+
case namesys.ErrResolveFailed:
99100
node = ft.EmptyDirNode()
100101
default:
101102
log.Errorf("looking up %s: %s", key.Path(), err)

0 commit comments

Comments
 (0)