Handle more errors

This commit is contained in:
Yannick Ulrich 2023-03-01 18:08:58 +00:00
parent 673383f795
commit a54ca7afdf
2 changed files with 28 additions and 6 deletions

10
fuse.go
View File

@ -12,7 +12,15 @@ import (
func startFUSE(ctx context.Context, dev *infinitime.Device) error {
// This is where we'll mount the FS
os.Mkdir(k.String("fuse.mountpoint"), 0755)
root := fusefs.BuildRootNode(dev)
root, err := fusefs.BuildRootNode(dev)
if err != nil {
log.Error("Building root node failed").
Err(err).
Send()
return err
return err
}
server, err := fs.Mount(k.String("fuse.mountpoint"), root, &fs.Options{
MountOptions: fuse.MountOptions{
// Set to true to see how the file system works.

View File

@ -39,11 +39,16 @@ type ITNode struct {
var myfs *blefs.FS = nil
var inodemap map[string]uint64 = nil
func BuildRootNode(dev *infinitime.Device) *ITNode {
func BuildRootNode(dev *infinitime.Device) (*ITNode, error) {
var err error
inodemap = make(map[string]uint64)
myfs, _ = dev.FS()
myfs, err = dev.FS()
if err != nil {
log.Error("FUSE failed to get filesystem").Err(err).Send()
return nil, err
}
return &ITNode{kind: 0}
return &ITNode{kind: 0}, nil
}
var properties = make([]ITProperty, 6)
@ -118,12 +123,21 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
case 2:
// on device
files, _ := myfs.ReadDir(n.path)
files, err := myfs.ReadDir(n.path)
if err != nil {
log.Error("ReadDir failed").Str("path", n.path).Err(err).Send()
return nil, syscall.ENOENT
}
log.Info("readdir").Str("path", n.path).Int("objects", len(files)).Send()
r := make([]fuse.DirEntry, len(files))
n.lst = make([]DirEntry, len(files))
for ind, entry := range files {
info, _ := entry.Info()
info, err := entry.Info()
if err != nil {
log.Error("Info failed").Str("path", n.path).Err(err).Send()
return nil, syscall.ENOENT
}
name := info.Name()
file := DirEntry{