Пример #1
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
}
Пример #2
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
}
Пример #3
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
}
Пример #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
}
Пример #5
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
}
Пример #6
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
}