diff --git a/fuse/main.go b/fuse/main.go index 31ee6d6..21c6497 100644 --- a/fuse/main.go +++ b/fuse/main.go @@ -3,12 +3,11 @@ package main import ( "go.arsenm.dev/logger/log" "os" - "context" - "syscall" + "context" + "syscall" "github.com/hanwen/go-fuse/v2/fs" "github.com/hanwen/go-fuse/v2/fuse" "strconv" - "strings" ) func (i *Device) HeartRateBytes() ([]byte, error) { @@ -43,6 +42,14 @@ type ITProperty struct { f func() ([]byte, error) } + +type DirEntry struct { + isDir bool + modtime uint64 + size uint32 + path string +} + type ITNode struct { fs.Inode kind int @@ -102,9 +109,18 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) { files, _ := myfs.ReadDir(n.path) log.Info("readdir").Str("path", n.path).Int("objects", len(files)).Send() r := make([]fuse.DirEntry, len(files)) - n.lst = files - for ind, file := range files { - name := file.path[strings.LastIndex(file.path, "/")+1:] + n.lst = make([]DirEntry, len(files)) + for ind, entry := range files { + info, _ := entry.Info() + name := info.Name() + + file := DirEntry{ + path: n.path + "/" + name, + size: uint32(info.Size()), + modtime: uint64(info.ModTime().Unix()), + isDir: info.IsDir(), + } + n.lst[ind] = file ino := inodemap[file.path] if ino == 0 { @@ -112,7 +128,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) { inodemap[file.path] = ino } - if file.flags & 0b1 == 1 { + if file.isDir { r[ind] = fuse.DirEntry{ Name: name, Mode: fuse.S_IFDIR, @@ -177,7 +193,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (* } log.Info("LookUp successful").Str("path", file.path).Send() - if file.flags & 0b1 == 1 { + if file.isDir { stable := fs.StableAttr{ Mode: fuse.S_IFDIR, Ino: inodemap[file.path], @@ -483,7 +499,7 @@ func main() { Str("target", mntDir). Err(err). Send() - return err + return } dev := Device{}; diff --git a/fuse/mock.go b/fuse/mock.go index 9487758..b7cceb1 100644 --- a/fuse/mock.go +++ b/fuse/mock.go @@ -3,6 +3,7 @@ import ( "os" "io/ioutil" "errors" + "time" ) const ( @@ -26,12 +27,30 @@ type Device struct { type FS struct { } -type DirEntry struct { - status int8 - flags uint32 - modtime uint64 - size uint32 - path string +type MyFileInfo struct { + name string + size uint32 + modtime time.Time + dir bool +} +func (n *MyFileInfo) Name() string { + return n.name +} +func (n *MyFileInfo) Size() uint32 { + return n.size +} +func (n *MyFileInfo) ModTime() time.Time { + return n.modtime +} +func (n *MyFileInfo) IsDir() bool { + return n.dir +} + +type MyDirEntry struct { + self MyFileInfo +} +func (n *MyDirEntry) Info() (MyFileInfo, error) { + return n.self, nil } type File struct { @@ -74,8 +93,8 @@ func (i *Device) Version() (string, error) { return "1.11.0", nil } -func (blefs *FS) ReadDir(path string) ([]DirEntry, error) { - var out []DirEntry +func (blefs *FS) ReadDir(path string) ([]MyDirEntry, error) { + var out []MyDirEntry files, err := ioutil.ReadDir("./root/" + path) if err != nil { @@ -83,17 +102,12 @@ func (blefs *FS) ReadDir(path string) ([]DirEntry, error) { } for _, f := range files { - listing := DirEntry{} - listing.status = FSStatusOk - listing.modtime = uint64(f.ModTime().Unix()) + listing := MyFileInfo{} + listing.modtime = f.ModTime() listing.size = uint32(f.Size()) - listing.path = path + "/" + f.Name() - if f.IsDir() { - listing.flags = 1; - } else { - listing.flags = 0; - } - out = append(out, listing) + listing.name = path + "/" + f.Name() + listing.dir = f.IsDir() + out = append(out, MyDirEntry{self : listing}) } return out, nil }