func (fh *FileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { glog.Infof("Entered Read.\n") //TODO: Check if we need to add something here for playlists and drop directories. if fh.r == nil { if fh.f.name == ".description" { glog.Info("Reading description file\n") if len(fh.f.artist) < 1 { return fuse.ENOENT } _, err := store.GetArtistPath(fh.f.artist) if err != nil { return err } if len(fh.f.album) > 1 { _, err = store.GetAlbumPath(fh.f.artist, fh.f.album) if err != nil { return err } } descBytes, err := store.GetDescription(fh.f.artist, fh.f.album, fh.f.name) if err != nil { return err } resp.Data = []byte(descBytes) return nil } glog.Info("There is no file handler.\n") return fuse.EIO } glog.Infof("Reading file: %s.\n", fh.r.Name()) if _, err := fh.r.Seek(req.Offset, 0); err != nil { return err } buf := make([]byte, req.Size) n, err := fh.r.Read(buf) resp.Data = buf[:n] if err != nil && err != io.EOF { glog.Error(err) return err } return nil }
func (d *Dir) Lookup(ctx context.Context, name string) (fs.Node, error) { glog.Infof("Entering Lookup with artist: %s, album: %s and name: %s.\n", d.artist, d.album, name) if name == ".description" { return &File{artist: d.artist, album: d.album, song: name, name: name, mPoint: d.mPoint}, nil } if name[0] == '.' { return nil, fuse.EIO } if len(d.artist) < 1 { if name == "drop" { return &Dir{fs: d.fs, artist: "drop", album: "", mPoint: d.mPoint}, nil } if name == "playlists" { return &Dir{fs: d.fs, artist: "playlists", album: "", mPoint: d.mPoint}, nil } _, err := store.GetArtistPath(name) if err != nil { glog.Info(err) return nil, err } return &Dir{fs: d.fs, artist: name, album: "", mPoint: d.mPoint}, nil } if len(d.album) < 1 && d.artist != "drop" && d.artist != "playlists" { _, err := store.GetAlbumPath(d.artist, name) if err != nil { glog.Info(err) return nil, err } return &Dir{fs: d.fs, artist: d.artist, album: name, mPoint: d.mPoint}, nil } var err error if d.artist == "drop" { _, err = store.GetDropFilePath(name, d.mPoint) if err != nil { glog.Info(err) return nil, fuse.ENOENT } } else if d.artist == "playlists" { if len(d.album) < 1 { _, err = store.GetPlaylistPath(name) if err != nil { glog.Info(err) return nil, fuse.ENOENT } return &Dir{fs: d.fs, artist: d.artist, album: name, mPoint: d.mPoint}, nil } else { _, err = store.GetPlaylistFilePath(d.album, name, d.mPoint) if err != nil { glog.Info(err) return nil, fuse.ENOENT } } } else { _, err = store.GetFilePath(d.artist, d.album, name) if err != nil { glog.Info(err) return nil, err } } extension := filepath.Ext(name) songName := name[:len(name)-len(extension)] return &File{artist: d.artist, album: d.album, song: songName, name: name, mPoint: d.mPoint}, nil }