Skip to content

Commit

Permalink
chore: replace deprecated fuse errors by syscall.Errno
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Aug 15, 2023
1 parent 58eff8b commit 1f653b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
19 changes: 10 additions & 9 deletions fuse/ipns/ipns_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io"
"os"
"strings"
"syscall"

path "github.com/ipfs/boxo/coreiface/path"
dag "github.com/ipfs/boxo/ipld/merkledag"
Expand Down Expand Up @@ -158,7 +159,7 @@ func (r *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
switch name {
case "mach_kernel", ".hidden", "._.":
// Just quiet some log noise on OS X.
return nil, fuse.ENOENT
return nil, syscall.Errno(syscall.ENOENT)
}

if lnk, ok := r.LocalLinks[name]; ok {
Expand All @@ -173,7 +174,7 @@ func (r *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
case *FileNode:
return nd, nil
default:
return nil, fuse.EIO
return nil, syscall.Errno(syscall.EIO)
}
}

Expand All @@ -182,7 +183,7 @@ func (r *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
resolved, err := r.Ipfs.Name().Resolve(ctx, ipnsName)
if err != nil {
log.Warnf("ipns: namesys resolve error: %s", err)
return nil, fuse.ENOENT
return nil, syscall.Errno(syscall.ENOENT)
}

if resolved.Namespace() != "ipfs" {
Expand Down Expand Up @@ -274,7 +275,7 @@ func (d *Directory) Lookup(ctx context.Context, name string) (fs.Node, error) {
child, err := d.dir.Child(name)
if err != nil {
// todo: make this error more versatile.
return nil, fuse.ENOENT
return nil, syscall.Errno(syscall.ENOENT)
}

switch child := child.(type) {
Expand Down Expand Up @@ -312,7 +313,7 @@ func (d *Directory) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
if len(entries) > 0 {
return entries, nil
}
return nil, fuse.ENOENT
return nil, syscall.Errno(syscall.ENOENT)
}

func (fi *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
Expand Down Expand Up @@ -423,7 +424,7 @@ func (fi *FileNode) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.
if req.Flags&fuse.OpenTruncate != 0 {
if req.Flags.IsReadOnly() {
log.Error("tried to open a readonly file with truncate")
return nil, fuse.ENOTSUP
return nil, syscall.Errno(syscall.ENOTSUP)
}
log.Info("Need to truncate file!")
err := fd.Truncate(0)
Expand All @@ -434,7 +435,7 @@ func (fi *FileNode) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.
log.Info("Need to append to file!")
if req.Flags.IsReadOnly() {
log.Error("tried to open a readonly file with append")
return nil, fuse.ENOTSUP
return nil, syscall.Errno(syscall.ENOTSUP)
}

_, err := fd.Seek(0, io.SeekEnd)
Expand Down Expand Up @@ -486,7 +487,7 @@ func (d *Directory) Create(ctx context.Context, req *fuse.CreateRequest, resp *f
func (d *Directory) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
err := d.dir.Unlink(req.Name)
if err != nil {
return fuse.ENOENT
return syscall.Errno(syscall.ENOENT)
}
return nil
}
Expand Down Expand Up @@ -516,7 +517,7 @@ func (d *Directory) Rename(ctx context.Context, req *fuse.RenameRequest, newDir
}
case *FileNode:
log.Error("Cannot move node into a file!")
return fuse.EPERM
return syscall.Errno(syscall.EPERM)
default:
log.Error("Unknown node type for rename target dir!")
return errors.New("unknown fs node type")
Expand Down
22 changes: 11 additions & 11 deletions fuse/readonly/readonly_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,32 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
switch name {
case "mach_kernel", ".hidden", "._.":
// Just quiet some log noise on OS X.
return nil, fuse.ENOENT
return nil, syscall.Errno(syscall.ENOENT)
}

p, err := path.ParsePath(name)
if err != nil {
log.Debugf("fuse failed to parse path: %q: %s", name, err)
return nil, fuse.ENOENT
return nil, syscall.Errno(syscall.ENOENT)
}

nd, ndLnk, err := s.Ipfs.UnixFSPathResolver.ResolvePath(ctx, p)
if err != nil {
// todo: make this error more versatile.
return nil, fuse.ENOENT
return nil, syscall.Errno(syscall.ENOENT)
}

cidLnk, ok := ndLnk.(cidlink.Link)
if !ok {
log.Debugf("non-cidlink returned from ResolvePath: %v", ndLnk)
return nil, fuse.ENOENT
return nil, syscall.Errno(syscall.ENOENT)
}

// convert ipld-prime node to universal node
blk, err := s.Ipfs.Blockstore.Get(ctx, cidLnk.Cid)
if err != nil {
log.Debugf("fuse failed to retrieve block: %v: %s", cidLnk, err)
return nil, fuse.ENOENT
return nil, syscall.Errno(syscall.ENOENT)
}

var fnd ipld.Node
Expand All @@ -101,11 +101,11 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
fnd, err = mdag.RawNodeConverter(blk, nd)
default:
log.Error("fuse node was not a supported type")
return nil, fuse.ENOTSUP
return nil, syscall.Errno(syscall.ENOTSUP)
}
if err != nil {
log.Error("could not convert protobuf or raw node")
return nil, fuse.ENOENT
return nil, syscall.Errno(syscall.ENOENT)
}

return &Node{Ipfs: s.Ipfs, Nd: fnd}, nil
Expand All @@ -114,7 +114,7 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
// ReadDirAll reads a particular directory. Disallowed for root.
func (*Root) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
log.Debug("read Root")
return nil, fuse.EPERM
return nil, syscall.Errno(syscall.EPERM)
}

// Node is the core object representing a filesystem tree node.
Expand Down Expand Up @@ -178,12 +178,12 @@ func (s *Node) Lookup(ctx context.Context, name string) (fs.Node, error) {
switch err {
case os.ErrNotExist, mdag.ErrLinkNotFound:
// todo: make this error more versatile.
return nil, fuse.ENOENT
return nil, syscall.Errno(syscall.ENOENT)
case nil:
// noop
default:
log.Errorf("fuse lookup %q: %s", name, err)
return nil, fuse.EIO
return nil, syscall.Errno(syscall.EIO)
}

nd, err := s.Ipfs.DAG.Get(ctx, link.Cid)
Expand Down Expand Up @@ -246,7 +246,7 @@ func (s *Node) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
if len(entries) > 0 {
return entries, nil
}
return nil, fuse.ENOENT
return nil, syscall.Errno(syscall.ENOENT)
}

func (s *Node) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error {
Expand Down

0 comments on commit 1f653b8

Please sign in to comment.