package kubelwagen import ( "github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse/pathfs" "github.com/sirupsen/logrus" ) type WsFs struct { pathfs.FileSystem req chan RequestCallback } type WsFsOpts struct { ReadOnly bool } func NewWsFs(opts WsFsOpts, req chan RequestCallback, closer chan bool) *pathfs.PathNodeFs { var fs pathfs.FileSystem wfs := &WsFs{ FileSystem: pathfs.NewDefaultFileSystem(), req: req, } // TODO(barakmich): spin up a goroutine to handle notify requests fs = wfs if opts.ReadOnly { fs = pathfs.NewReadonlyFileSystem(fs) } return pathfs.NewPathNodeFs(fs, nil) } func getChannel() chan Response { return make(chan Response) } func (fs *WsFs) String() string { return "kubelwagen" } func (fs *WsFs) OpenDir(name string, context *fuse.Context) ([]fuse.DirEntry, fuse.Status) { r := Request{ Method: MethodOpenDir, Path: name, } c := getChannel() fs.req <- RequestCallback{ message: r, response: c, } resp, ok := <-c if !ok { logrus.Errorln("Response to request channel closed") return fs.FileSystem.OpenDir(name, context) } return resp.Dirents, resp.Code } func (fs *WsFs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) { r := Request{ Method: MethodGetAttr, Path: name, } c := getChannel() fs.req <- RequestCallback{ message: r, response: c, } resp, ok := <-c if !ok { logrus.Errorln("Response to request channel closed") return fs.FileSystem.GetAttr(name, context) } return resp.Stat, resp.Code }