func processNewAlbum(newArtist, newAlbum, oldArtist, oldAlbum string) ([][]byte, error) {
	var songs [][]byte
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		glog.Error("Error opening the database.")
		return nil, err
	}
	defer db.Close()
	newAlbumRaw := newAlbum
	newAlbum = GetCompatibleString(newAlbum)
	err = db.Update(func(tx *bolt.Tx) error {
		root := tx.Bucket([]byte("Artists"))
		artistBucket := root.Bucket([]byte(newArtist))
		if artistBucket == nil {
			glog.Info("Destination Artist not found.")
			return errors.New("Artist not found.")
		}
		albumBucket, err := artistBucket.CreateBucketIfNotExists([]byte(newAlbum))
		if err != nil {
			glog.Info("Cannot create Album bucket.")
			return fuse.EIO
		}
		description := albumBucket.Get([]byte(".description"))
		if description == nil {
			albumStore := &AlbumStore{
				AlbumName: newAlbumRaw,
				AlbumPath: newAlbum,
			}
			encoded, err := json.Marshal(albumStore)
			if err != nil {
				glog.Info("Cannot encode description JSON.")
				return fuse.EIO
			}
			albumBucket.Put([]byte(".description"), encoded)
		}
		var artistStore ArtistStore
		descValue := artistBucket.Get([]byte(".description"))
		if descValue == nil {
			artistStore.ArtistName = newArtist
			artistStore.ArtistPath = newArtist
			artistStore.ArtistAlbums = []string{newAlbum}
		} else {
			err := json.Unmarshal(descValue, &artistStore)
			if err != nil {
				artistStore.ArtistName = newArtist
				artistStore.ArtistPath = newArtist
				artistStore.ArtistAlbums = []string{newAlbum}
			}
			var found bool = false
			for _, a := range artistStore.ArtistAlbums {
				if a == newAlbum {
					found = true
					break
				}
			}
			if found == false {
				artistStore.ArtistAlbums = append(artistStore.ArtistAlbums, newAlbum)
			}
		}
		encoded, err := json.Marshal(artistStore)
		if err != nil {
			return err
		}
		artistBucket.Put([]byte(".description"), encoded)
		oldArtistBucket := root.Bucket([]byte(oldArtist))
		if oldArtistBucket == nil {
			glog.Info("Source Artist not found.")
			return errors.New("Artist not found")
		}
		oldAlbumBucket := oldArtistBucket.Bucket([]byte(oldAlbum))
		if oldAlbumBucket == nil {
			glog.Info("Source Album not found.")
			return errors.New("Album not found")
		}
		descValue = oldArtistBucket.Get([]byte(".description"))
		if descValue != nil {
			err := json.Unmarshal(descValue, &artistStore)
			if err == nil {
				for i, a := range artistStore.ArtistAlbums {
					if a == oldAlbum {
						artistStore.ArtistAlbums = append(artistStore.ArtistAlbums[:i], artistStore.ArtistAlbums[i+1:]...)
						break
					}
				}
				encoded, err := json.Marshal(artistStore)
				if err != nil {
					return err
				}
				oldArtistBucket.Put([]byte(".description"), encoded)
			}
		}
		c := oldAlbumBucket.Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			var temp []byte
			if k[0] == '.' {
				continue
			}
			temp = make([]byte, len(v))
			copy(temp, v)
			songs = append(songs, temp)
		}
		return nil
	})
	return songs, err
}
processNewAlbum returns all the songs inside an Album and
prepares the new folder for the new Album.
It also creates the description files and Buckets in the DB.
package store
import (
	"encoding/json"
	"errors"
	"github.com/dankomiocevic/mulifs/musicmgr"
	"github.com/dankomiocevic/mulifs/playlistmgr"
	"os"
	"path/filepath"
	"bazil.org/fuse"
	"github.com/boltdb/bolt"
	"github.com/golang/glog"
)
func MoveSongs(oldArtist, oldAlbum, oldName, newArtist, newAlbum, newName, path, mPoint string) (string, error) {
	glog.Infof("Moving song from Artist: %s, Album: %s, name: %s and path: %s to Artist: %s, Album: %s, name: %s\n", oldArtist, oldAlbum, oldName, path, newArtist, newAlbum, newName)
	extension := filepath.Ext(path)
	if extension != ".mp3" {
		glog.Info("Wrong file format.")
		return "", errors.New("Wrong file format.")
	}
	rootPoint := mPoint
	if rootPoint[len(rootPoint)-1] != '/' {
		rootPoint = rootPoint + "/"
	}
	newFileName := GetCompatibleString(newName[:len(newName)-len(extension)]) + extension
	newPath := rootPoint + newArtist + "/" + newAlbum + "/"
	newFullPath := newPath + newFileName
	songStore, err := GetSong(oldArtist, oldAlbum, oldName)
	if err != nil {
		glog.Infof("Cannot get the file from the database: %s\n", err)
	}
	for _, pl := range songStore.Playlists {
		DeletePlaylistSong(pl, oldName, true)
	}
	err = os.Rename(path, newFullPath)
	if err != nil {
		glog.Infof("Cannot rename the file: %s\n", err)
		return "", err
	}
	err = DeleteSong(oldArtist, oldAlbum, oldName, mPoint)
	if err != nil {
		glog.Infof("Cannot delete song: %s\n", err)
		return "", err
	}
	musicmgr.SetMp3Tags(newArtist, newAlbum, newName, newFullPath)
	_, err = CreateSong(newArtist, newAlbum, newName, newPath)
	if err != nil {
		glog.Infof("Cannot create song in the db: %s\n", err)
		return "", err
	}
	for _, pl := range songStore.Playlists {
		file := playlistmgr.PlaylistFile{
			Title:  newName,
			Artist: newArtist,
			Album:  newAlbum,
			Path:   newPath,
		}
		AddFileToPlaylist(file, pl)
		RegeneratePlaylistFile(pl, mPoint)
	}
	return newFileName, nil
}
func processNewArtist(newArtist, oldArtist string) ([]string, error) {
	var albums []string
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		glog.Error("Error opening the database.")
		return nil, err
	}
	defer db.Close()
	newArtistRaw := newArtist
	newArtist = GetCompatibleString(newArtist)
	err = db.Update(func(tx *bolt.Tx) error {
		root := tx.Bucket([]byte("Artists"))
		oldArtistBucket := root.Bucket([]byte(oldArtist))
		if oldArtistBucket == nil {
			glog.Info("Source Artist not found.")
			return errors.New("Artist not found")
		}
		oldDescription := oldArtistBucket.Get([]byte(".description"))
		if oldDescription != nil {
			var oldArtistStore ArtistStore
			err := json.Unmarshal(oldDescription, &oldArtistStore)
			if err == nil {
				albums = make([]string, len(oldArtistStore.ArtistAlbums))
				copy(albums, oldArtistStore.ArtistAlbums)
			} else {
				albums = make([]string, 0)
			}
		}
		artistBucket, err := root.CreateBucketIfNotExists([]byte(newArtist))
		if err != nil {
			glog.Info("Cannot create Artist bucket.")
			return fuse.EIO
		}
		description := artistBucket.Get([]byte(".description"))
		var artistStore ArtistStore
		if description == nil {
			artistStore = ArtistStore{
				ArtistName:   newArtistRaw,
				ArtistPath:   newArtist,
				ArtistAlbums: albums,
			}
		} else {
			err := json.Unmarshal(description, &artistStore)
			if err != nil {
				return fuse.EIO
			}
			copy(artistStore.ArtistAlbums, albums)
		}
		encoded, err := json.Marshal(artistStore)
		if err != nil {
			glog.Info("Cannot encode description JSON.")
			return fuse.EIO
		}
		artistBucket.Put([]byte(".description"), encoded)
		return nil
	})
	return albums, err
}