forked from len0rd/rockbox
playlist: Simplify playlist_load
Reset fd for the on-disk playlist at the place where ownership is transferred in playlist_set_current (which already has a note, that the playlist will be effectively closed, but did not reset the fd). Also ensure, that calling playlist_load closes the fd for the on-disk playlist (and its control file), if any were left open - even though this is not supposed to happen. Generate name of control file in playlist_init to be more consistent with the behavior for the current playlist. Only a single playlist can be loaded in the playlist viewer at the same time, so generating random names shouldn't be needed. Change-Id: I65e0fc07ce608c1d333a90447e18482787a98b8c
This commit is contained in:
parent
5d9b01b9ed
commit
0012411fc5
2 changed files with 26 additions and 26 deletions
|
@ -476,11 +476,7 @@ static void update_playlist_filename_unlocked(struct playlist_info* playlist,
|
|||
static void empty_playlist_unlocked(struct playlist_info* playlist, bool resume)
|
||||
{
|
||||
pl_close_playlist(playlist);
|
||||
|
||||
if(playlist->control_fd >= 0)
|
||||
{
|
||||
close(playlist->control_fd);
|
||||
}
|
||||
pl_close_control(playlist);
|
||||
|
||||
playlist->filename[0] = '\0';
|
||||
|
||||
|
@ -490,8 +486,6 @@ static void empty_playlist_unlocked(struct playlist_info* playlist, bool resume)
|
|||
playlist->control_created = false;
|
||||
playlist->flags = 0;
|
||||
|
||||
playlist->control_fd = -1;
|
||||
|
||||
playlist->index = 0;
|
||||
playlist->first_index = 0;
|
||||
playlist->amount = 0;
|
||||
|
@ -1941,10 +1935,16 @@ void playlist_init(void)
|
|||
mutex_init(¤t_playlist.mutex);
|
||||
mutex_init(&on_disk_playlist.mutex);
|
||||
|
||||
strmemccpy(playlist->control_filename, PLAYLIST_CONTROL_FILE,
|
||||
sizeof(playlist->control_filename));
|
||||
playlist->fd = -1;
|
||||
playlist->control_fd = -1;
|
||||
strmemccpy(current_playlist.control_filename, PLAYLIST_CONTROL_FILE,
|
||||
sizeof(current_playlist.control_filename));
|
||||
|
||||
strmemccpy(on_disk_playlist.control_filename, PLAYLIST_CONTROL_FILE ".tmp",
|
||||
sizeof(on_disk_playlist.control_filename));
|
||||
|
||||
current_playlist.fd = -1;
|
||||
on_disk_playlist.fd = -1;
|
||||
current_playlist.control_fd = -1;
|
||||
on_disk_playlist.control_fd = -1;
|
||||
playlist->max_playlist_size = global_settings.max_files_in_playlist;
|
||||
|
||||
handle = core_alloc_ex(playlist->max_playlist_size * sizeof(*playlist->indices), &ops);
|
||||
|
@ -2018,7 +2018,8 @@ size_t playlist_get_index_bufsz(size_t max_sz)
|
|||
|
||||
/*
|
||||
* Load a playlist off disk for viewing/editing.
|
||||
* Make sure to close a previously loaded playlist before calling this again!
|
||||
* This will close a previously loaded playlist and its control file,
|
||||
* if one has been left open.
|
||||
*
|
||||
* The index_buffer is used to store playlist indices. If no index buffer is
|
||||
* provided, the current playlist's index buffer is shared.
|
||||
|
@ -2033,16 +2034,6 @@ struct playlist_info* playlist_load(const char* dir, const char* file,
|
|||
void* temp_buffer, int temp_buffer_size)
|
||||
{
|
||||
struct playlist_info* playlist = &on_disk_playlist;
|
||||
|
||||
/* Initialize playlist structure */
|
||||
int r = rand() % 10;
|
||||
|
||||
/* Use random name for control file */
|
||||
snprintf(playlist->control_filename, sizeof(playlist->control_filename),
|
||||
"%s.%d", PLAYLIST_CONTROL_FILE, r);
|
||||
playlist->fd = -1;
|
||||
playlist->control_fd = -1;
|
||||
|
||||
if (index_buffer)
|
||||
{
|
||||
int num_indices = index_buffer_size / sizeof(*playlist->indices);
|
||||
|
@ -3581,7 +3572,10 @@ int playlist_set_current(struct playlist_info* playlist)
|
|||
int result = -1;
|
||||
|
||||
if (!playlist || (check_control(playlist) < 0))
|
||||
{
|
||||
playlist_close(playlist);
|
||||
return result;
|
||||
}
|
||||
|
||||
dc_thread_stop(¤t_playlist);
|
||||
playlist_write_lock(¤t_playlist);
|
||||
|
@ -3592,7 +3586,10 @@ int playlist_set_current(struct playlist_info* playlist)
|
|||
sizeof(current_playlist.filename));
|
||||
|
||||
current_playlist.utf8 = playlist->utf8;
|
||||
|
||||
/* Transfer ownership of fd to current playlist */
|
||||
current_playlist.fd = playlist->fd;
|
||||
playlist->fd = -1;
|
||||
|
||||
pl_close_control(playlist);
|
||||
pl_close_control(¤t_playlist);
|
||||
|
|
|
@ -1066,12 +1066,10 @@ enum playlist_viewer_result playlist_viewer_ex(const char* filename,
|
|||
struct playlist_entry * current_track =
|
||||
playlist_buffer_get_track(&viewer.buffer,
|
||||
viewer.selected_track);
|
||||
|
||||
int ret_val;
|
||||
if (viewer.moving_track >= 0)
|
||||
{
|
||||
/* Move track */
|
||||
int ret_val;
|
||||
|
||||
ret_val = playlist_move(viewer.playlist,
|
||||
viewer.moving_playlist_index,
|
||||
current_track->index);
|
||||
|
@ -1108,7 +1106,12 @@ enum playlist_viewer_result playlist_viewer_ex(const char* filename,
|
|||
break;
|
||||
}
|
||||
/* New playlist */
|
||||
if (playlist_set_current(viewer.playlist) < 0)
|
||||
ret_val = playlist_set_current(viewer.playlist);
|
||||
|
||||
/* Playlist effectively closed */
|
||||
viewer.playlist = NULL;
|
||||
|
||||
if (ret_val < 0)
|
||||
goto exit;
|
||||
if (global_settings.playlist_shuffle)
|
||||
start_index = playlist_shuffle(current_tick, start_index);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue