Example #1
0
// ListPlaylists function returns all the names of the playlists available
// in the MuLi system.
// It receives no arguments and returns a slice of Dir objects to list
// all the available playlists and the error if there is any.
func ListPlaylists() ([]fuse.Dirent, error) {
	glog.Info("Entered list playlists.")
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		return nil, err
	}
	defer db.Close()

	var a []fuse.Dirent
	err = db.View(func(tx *bolt.Tx) error {
		b := tx.Bucket([]byte("Playlists"))
		if b == nil {
			glog.Infof("There is no Playlists bucket.")
			return nil
		}
		c := b.Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			if v == nil {
				var node fuse.Dirent
				node.Name = string(k)
				node.Type = fuse.DT_Dir
				a = append(a, node)
			}
		}
		return nil
	})
	return a, nil
}
Example #2
0
// ReadDirAll implements the fs.NodeReadDirAller interface for Dir.
func (d *Dir) ReadDirAll(ctx context.Context) (res []fuse.Dirent, err error) {
	ctx = NewContextWithOpID(ctx, d.folder.fs.log)
	d.folder.fs.log.CDebugf(ctx, "Dir ReadDirAll")
	defer func() { d.folder.fs.reportErr(ctx, err) }()

	children, err := d.folder.fs.config.KBFSOps().GetDirChildren(ctx, d.node)
	if err != nil {
		return nil, err
	}

	for name, ei := range children {
		fde := fuse.Dirent{
			Name: name,
		}
		switch ei.Type {
		case libkbfs.File, libkbfs.Exec:
			fde.Type = fuse.DT_File
		case libkbfs.Dir:
			fde.Type = fuse.DT_Dir
		case libkbfs.Sym:
			fde.Type = fuse.DT_Link
		}
		res = append(res, fde)
	}
	return res, nil
}
Example #3
0
func (d *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
	d.RLock()
	log.Println("ReadDirAll ", d.path)
	var out []fuse.Dirent
	files, err := ioutil.ReadDir(d.path)
	if err != nil {
		log.Println("ReadDirAll ERR: ", err)
		return nil, err
	}

	for _, node := range files {
		de := fuse.Dirent{Name: node.Name()}
		if node.IsDir() {
			de.Type = fuse.DT_Dir
		}
		if node.Mode().IsRegular() {
			de.Type = fuse.DT_File
		}
		log.Println("ReadDirAll file", de)
		out = append(out, de)
	}

	d.RUnlock()
	return out, nil
}
Example #4
0
// ListSongs returns all the Dirent corresponding
// to Songs for a specified Artist and Album
// in the database.
// This is used to generate the Song listing on the
// generated filesystem.
// It returns nil in the second return value if there
// was no error and nil if the Songs were
// obtained correctly.
func ListSongs(artist string, album string) ([]fuse.Dirent, error) {
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		return nil, err
	}
	defer db.Close()

	var a []fuse.Dirent
	err = db.View(func(tx *bolt.Tx) error {
		root := tx.Bucket([]byte("Artists"))
		artistBucket := root.Bucket([]byte(artist))
		b := artistBucket.Bucket([]byte(album))
		c := b.Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			var song SongStore
			if k[0] != '.' || string(k) == ".description" {
				err := json.Unmarshal(v, &song)
				if err != nil {
					continue
				}
			}
			var node fuse.Dirent
			node.Name = string(k)
			node.Type = fuse.DT_File
			a = append(a, node)
		}
		return nil
	})

	if err != nil {
		return nil, err
	}

	return a, nil
}
Example #5
0
func (d fuseDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
	var list []fuse.Dirent
	it := d.reader.Iter()
	var de *wire.Dirent
	var err error
	for {
		de, err = it.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			return list, fmt.Errorf("snap readdir error: %v", err)
		}
		fde := fuse.Dirent{
			Name: de.Name,
		}
		if de.File != nil {
			fde.Type = fuse.DT_File
		} else if de.Dir != nil {
			fde.Type = fuse.DT_Dir
		}
		list = append(list, fde)
	}
	return list, nil
}
Example #6
0
func (d *Dir) ReadDirAll(c context.Context) ([]fuse.Dirent, error) {
	var res []fuse.Dirent
	err := d.fs.backend.View(c, func(ctx Context) error {
		b, err := ctx.Dir(d.path)
		if err != nil {
			return err
		}
		if b == nil {
			return errors.New("dir no longer exists")
		}
		for entry := range b.Cursor() {
			de := fuse.Dirent{
				Name: entry.Name,
			}
			if entry.Dir {
				de.Type = fuse.DT_Dir
			} else {
				de.Type = fuse.DT_File
			}
			res = append(res, de)
		}
		return nil
	})
	return res, err
}
Example #7
0
func (n Node) asDirent() fuse.Dirent {
	var d fuse.Dirent

	d.Name = n.Name
	d.Inode = n.Inode
	if os.ModeDir&n.Mode > 0 {
		d.Type = fuse.DT_Dir
	} else {
		d.Type = fuse.DT_File
	}

	return d
}
Example #8
0
// GetFUSEDirent returns a populated fuse.Dirent
func (d *Dirent) GetFUSEDirent(name string) fuse.Dirent {
	fde := fuse.Dirent{
		Inode: d.Inode,
		Name:  name,
	}
	switch {
	case d.Type.File != nil:
		fde.Type = fuse.DT_File

	case d.Type.Dir != nil:
		fde.Type = fuse.DT_Dir
	}
	return fde
}
Example #9
0
func (d *Dir) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) {
	var out []fuse.Dirent

	d.rwmut.RLock()
	for name, node := range d.Children {
		de := fuse.Dirent{Name: name}
		switch node.(type) {
		case *Dir:
			de.Type = fuse.DT_Dir
		case *File:
			de.Type = fuse.DT_Dir
		}
		out = append(out, de)
	}
	d.rwmut.RUnlock()

	return out, nil
}
Example #10
0
func (d Dir) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) {
	var out []fuse.Dirent
	files, err := ioutil.ReadDir(d.Path)
	if err != nil {
		log.Print(err)
		return nil, fuse.Errno(err.(syscall.Errno))
	}
	for _, node := range files {
		de := fuse.Dirent{Name: node.Name()}
		if node.IsDir() {
			de.Type = fuse.DT_Dir
		}
		if node.Mode().IsRegular() {
			de.Type = fuse.DT_File
		}
		out = append(out, de)
	}

	return out, nil
}
Example #11
0
// ListAlbums returns all the Dirent corresponding
// to Albums for a specified Artist in the database.
// This is used to generate the Album listing on the
// generated filesystem.
// It returns nil in the second return value if there
// was no error and nil if the Albums were
// obtained correctly.
func ListAlbums(artist string) ([]fuse.Dirent, error) {
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		return nil, err
	}
	defer db.Close()

	var a []fuse.Dirent
	err = db.View(func(tx *bolt.Tx) error {
		root := tx.Bucket([]byte("Artists"))
		b := root.Bucket([]byte(artist))
		c := b.Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			if v == nil {
				var node fuse.Dirent
				node.Name = string(k)
				node.Type = fuse.DT_Dir
				a = append(a, node)
			} else {
				var node fuse.Dirent
				node.Name = string(k)
				node.Type = fuse.DT_File
				a = append(a, node)
			}
		}
		return nil
	})

	if err != nil {
		return nil, err
	}

	return a, nil
}
Example #12
0
func (dn dirNode) ReadDirAll(ctx context.Context) (des []fuse.Dirent, err error) {
	names := map[string]bool{}
	for _, fi := range dn.metadata.Files {
		if !isSubPath(dn.path, strings.Join(fi.Path, "/")) {
			continue
		}
		name := fi.Path[len(dn.path)]
		if names[name] {
			continue
		}
		names[name] = true
		de := fuse.Dirent{
			Name: name,
		}
		if len(fi.Path) == len(dn.path)+1 {
			de.Type = fuse.DT_File
		} else {
			de.Type = fuse.DT_Dir
		}
		des = append(des, de)
	}
	return
}
Example #13
0
func (d *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
	var res []fuse.Dirent
	err := d.fs.db.View(func(tx *bolt.Tx) error {
		b := d.bucket(tx)
		if b == nil {
			return errors.New("bucket no longer exists")
		}
		c := b.Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			de := fuse.Dirent{
				Name: EncodeKey(k),
			}
			if v == nil {
				de.Type = fuse.DT_Dir
			} else {
				de.Type = fuse.DT_File
			}
			res = append(res, de)
		}
		return nil
	})
	return res, err
}
Example #14
0
func (d *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
	var readDirReply = []fuse.Dirent{}

	fmt.Println("Dir.ReadDirAll", d.path)
	list := d.fs.c.List(d.path)
	d.fs.cache[d.path] = list

	for _, entry := range list.Result {
		f := fuse.Dirent{
			Inode: 0,
			Name:  entry.Name,
			Type:  fuse.DT_File,
		}

		if entry.IsDir {
			f.Type = fuse.DT_Dir
		} else if entry.IsSymlink {
			f.Type = fuse.DT_Link
		}
		readDirReply = append(readDirReply, f)
	}

	return readDirReply, nil
}
Example #15
0
// ListPlaylistSongs function returns all the songs inside a playlist.
// The available songs are loaded from the database and also from the
// temporary drop directory named after the playlist.
// It receives a playlist name and returns a slice with all the
// files.
func ListPlaylistSongs(playlist, mPoint string) ([]fuse.Dirent, error) {
	glog.Infof("Listing contents of playlist %s.\n", playlist)
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		return nil, err
	}
	defer db.Close()

	var a []fuse.Dirent
	err = db.View(func(tx *bolt.Tx) error {
		root := tx.Bucket([]byte("Playlists"))
		if root == nil {
			return nil
		}

		b := root.Bucket([]byte(playlist))
		if b == nil {
			return nil
		}

		c := b.Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			if v != nil {
				var node fuse.Dirent
				node.Name = string(k)
				node.Type = fuse.DT_File
				a = append(a, node)
			}
		}
		return nil
	})

	if err != nil {
		return nil, err
	}

	if mPoint[len(mPoint)-1] != '/' {
		mPoint = mPoint + "/"
	}

	fullPath := mPoint + "playlists/" + playlist + "/"

	files, _ := ioutil.ReadDir(fullPath)
	for _, f := range files {
		if !f.IsDir() {
			var node fuse.Dirent
			node.Name = string(f.Name())
			node.Type = fuse.DT_File
			a = append(a, node)
		}
	}
	return a, nil
}
Example #16
0
func (d *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
	glog.Infof("Entering ReadDirAll\n")
	if len(d.artist) < 1 {
		a, err := store.ListArtists()
		if err != nil {
			return nil, fuse.ENOENT
		}
		for _, v := range dirDirs {
			a = append(a, v)
		}
		return a, nil
	}

	if d.artist == "drop" {
		if len(d.album) > 0 {
			return nil, fuse.ENOENT
		}

		rootPoint := d.mPoint
		if rootPoint[len(rootPoint)-1] != '/' {
			rootPoint = rootPoint + "/"
		}

		path := rootPoint + "drop"
		// Check if the drop directory exists
		src, err := os.Stat(path)
		if err != nil {
			return nil, nil
		}

		// Check if it is a directory
		if !src.IsDir() {
			return nil, nil
		}

		var a []fuse.Dirent
		files, _ := ioutil.ReadDir(path)
		for _, f := range files {
			var node fuse.Dirent
			node.Name = f.Name()
			node.Type = fuse.DT_File
			a = append(a, node)
		}
		return a, nil
	}

	if d.artist == "playlists" {
		if len(d.album) < 1 {
			a, err := store.ListPlaylists()
			if err != nil {
				return nil, fuse.ENOENT
			}
			return a, nil
		}

		a, err := store.ListPlaylistSongs(d.album, d.mPoint)
		if err != nil {
			return nil, fuse.ENOENT
		}

		return a, nil
	}

	if len(d.album) < 1 {
		a, err := store.ListAlbums(d.artist)
		if err != nil {
			return nil, fuse.ENOENT
		}
		return a, nil
	}

	a, err := store.ListSongs(d.artist, d.album)
	if err != nil {
		return nil, fuse.ENOENT
	}

	return a, nil
}