func (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) error { if fh.r == nil { if fh.f.name == ".description" { glog.Infof("Entered Release: .description file\n") return nil } if fh.f.name[0] == '.' { return fuse.EPERM } } if fh.r == nil { glog.Info("Release: There is no file handler.\n") return fuse.EIO } glog.Infof("Releasing the file: %s\n", fh.r.Name()) if fh.f != nil && fh.f.artist == "drop" { glog.Infof("Entered Release dropping the song: %s\n", fh.f.name) ret_val := fh.r.Close() PushFileItem(*fh.f, DelayedHandleDrop) return ret_val } if fh.f != nil && fh.f.artist == "playlists" { glog.Infof("Entered Release with playlist song: %s\n", fh.f.name) ret_val := fh.r.Close() PushFileItem(*fh.f, DelayedHandlePlaylistSong) return ret_val } // This is not an music file or this is a strange situation. if fh.f == nil || len(fh.f.artist) < 1 || len(fh.f.album) < 1 { glog.Info("Entered Release: Artist or Album not set.\n") return fh.r.Close() } glog.Infof("Entered Release: Artist: %s, Album: %s, Song: %s\n", fh.f.artist, fh.f.album, fh.f.name) ret_val := fh.r.Close() extension := filepath.Ext(fh.f.name) songPath, err := store.GetFilePath(fh.f.artist, fh.f.album, fh.f.name) if err != nil { return err } if extension == ".mp3" { //TODO: Use the correct artist and album musicmgr.SetMp3Tags(fh.f.artist, fh.f.album, fh.f.song, songPath) } return ret_val }
// MoveSongs changes the Songs path. // It modifies the information in the database // and updates the tags to match the new location. // It also moves the actual file into the new // location. 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) // Check file extension. 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 // Get all the Playlists form the file. songStore, err := GetSong(oldArtist, oldAlbum, oldName) if err != nil { glog.Infof("Cannot get the file from the database: %s\n", err) } // Delete the song from all the playlists for _, pl := range songStore.Playlists { DeletePlaylistSong(pl, oldName, true) } // Rename the file err = os.Rename(path, newFullPath) if err != nil { glog.Infof("Cannot rename the file: %s\n", err) return "", err } // Delete the song from the database err = DeleteSong(oldArtist, oldAlbum, oldName, mPoint) if err != nil { glog.Infof("Cannot delete song: %s\n", err) return "", err } // Change the tags in the file. musicmgr.SetMp3Tags(newArtist, newAlbum, newName, newFullPath) // Add the song again to the database. _, err = CreateSong(newArtist, newAlbum, newName, newPath) if err != nil { glog.Infof("Cannot create song in the db: %s\n", err) return "", err } // Add the song to all the playlists. 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 }