Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+26 -26
+19 -22
apps/playlist.c
··· 476 476 static void empty_playlist_unlocked(struct playlist_info* playlist, bool resume) 477 477 { 478 478 pl_close_playlist(playlist); 479 - 480 - if(playlist->control_fd >= 0) 481 - { 482 - close(playlist->control_fd); 483 - } 479 + pl_close_control(playlist); 484 480 485 481 playlist->filename[0] = '\0'; 486 482 ··· 489 485 playlist->utf8 = true; 490 486 playlist->control_created = false; 491 487 playlist->flags = 0; 492 - 493 - playlist->control_fd = -1; 494 488 495 489 playlist->index = 0; 496 490 playlist->first_index = 0; ··· 1941 1935 mutex_init(&current_playlist.mutex); 1942 1936 mutex_init(&on_disk_playlist.mutex); 1943 1937 1944 - strmemccpy(playlist->control_filename, PLAYLIST_CONTROL_FILE, 1945 - sizeof(playlist->control_filename)); 1946 - playlist->fd = -1; 1947 - playlist->control_fd = -1; 1938 + strmemccpy(current_playlist.control_filename, PLAYLIST_CONTROL_FILE, 1939 + sizeof(current_playlist.control_filename)); 1940 + 1941 + strmemccpy(on_disk_playlist.control_filename, PLAYLIST_CONTROL_FILE ".tmp", 1942 + sizeof(on_disk_playlist.control_filename)); 1943 + 1944 + current_playlist.fd = -1; 1945 + on_disk_playlist.fd = -1; 1946 + current_playlist.control_fd = -1; 1947 + on_disk_playlist.control_fd = -1; 1948 1948 playlist->max_playlist_size = global_settings.max_files_in_playlist; 1949 1949 1950 1950 handle = core_alloc_ex(playlist->max_playlist_size * sizeof(*playlist->indices), &ops); ··· 2018 2018 2019 2019 /* 2020 2020 * Load a playlist off disk for viewing/editing. 2021 - * Make sure to close a previously loaded playlist before calling this again! 2021 + * This will close a previously loaded playlist and its control file, 2022 + * if one has been left open. 2022 2023 * 2023 2024 * The index_buffer is used to store playlist indices. If no index buffer is 2024 2025 * provided, the current playlist's index buffer is shared. ··· 2033 2034 void* temp_buffer, int temp_buffer_size) 2034 2035 { 2035 2036 struct playlist_info* playlist = &on_disk_playlist; 2036 - 2037 - /* Initialize playlist structure */ 2038 - int r = rand() % 10; 2039 - 2040 - /* Use random name for control file */ 2041 - snprintf(playlist->control_filename, sizeof(playlist->control_filename), 2042 - "%s.%d", PLAYLIST_CONTROL_FILE, r); 2043 - playlist->fd = -1; 2044 - playlist->control_fd = -1; 2045 - 2046 2037 if (index_buffer) 2047 2038 { 2048 2039 int num_indices = index_buffer_size / sizeof(*playlist->indices); ··· 3581 3572 int result = -1; 3582 3573 3583 3574 if (!playlist || (check_control(playlist) < 0)) 3575 + { 3576 + playlist_close(playlist); 3584 3577 return result; 3578 + } 3585 3579 3586 3580 dc_thread_stop(&current_playlist); 3587 3581 playlist_write_lock(&current_playlist); ··· 3592 3586 sizeof(current_playlist.filename)); 3593 3587 3594 3588 current_playlist.utf8 = playlist->utf8; 3589 + 3590 + /* Transfer ownership of fd to current playlist */ 3595 3591 current_playlist.fd = playlist->fd; 3592 + playlist->fd = -1; 3596 3593 3597 3594 pl_close_control(playlist); 3598 3595 pl_close_control(&current_playlist);
+7 -4
apps/playlist_viewer.c
··· 1066 1066 struct playlist_entry * current_track = 1067 1067 playlist_buffer_get_track(&viewer.buffer, 1068 1068 viewer.selected_track); 1069 - 1069 + int ret_val; 1070 1070 if (viewer.moving_track >= 0) 1071 1071 { 1072 1072 /* Move track */ 1073 - int ret_val; 1074 - 1075 1073 ret_val = playlist_move(viewer.playlist, 1076 1074 viewer.moving_playlist_index, 1077 1075 current_track->index); ··· 1108 1106 break; 1109 1107 } 1110 1108 /* New playlist */ 1111 - if (playlist_set_current(viewer.playlist) < 0) 1109 + ret_val = playlist_set_current(viewer.playlist); 1110 + 1111 + /* Playlist effectively closed */ 1112 + viewer.playlist = NULL; 1113 + 1114 + if (ret_val < 0) 1112 1115 goto exit; 1113 1116 if (global_settings.playlist_shuffle) 1114 1117 start_index = playlist_shuffle(current_tick, start_index);