diff --git a/apps/tagtree.c b/apps/tagtree.c index 1a49936f45..267fa4fba7 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -2205,34 +2205,35 @@ static bool insert_all_playlist(struct tree_context *c, bool fill_randomly = false; bool *rand_bool_array = NULL; char buf[MAX_PATH]; + struct playlist_insert_context context; cpu_boost(true); + if (!tagcache_search(&tcs, tag_filename)) { splash(HZ, ID2P(LANG_TAGCACHE_BUSY)); cpu_boost(false); return false; - } + } /* NOTE: you need to close this search before returning */ - if (playlist == NULL && position == PLAYLIST_REPLACE) + if (playlist == NULL) { - if (playlist_remove_all_tracks(NULL) == 0) - position = PLAYLIST_INSERT_LAST; - else + if (playlist_insert_context_create(NULL, &context, position, queue, false) < 0) { + tagcache_search_finish(&tcs); cpu_boost(false); return false; } } - else if (playlist != NULL) + else { if (new_playlist) fd = open_utf8(playlist, O_CREAT|O_WRONLY|O_TRUNC); else fd = open(playlist, O_CREAT|O_WRONLY|O_APPEND, 0666); - if(fd < 0) { + tagcache_search_finish(&tcs); cpu_boost(false); return false; } @@ -2249,6 +2250,7 @@ static bool insert_all_playlist(struct tree_context *c, if (slots_remaining <= 0) { logf("Playlist has no space remaining"); + tagcache_search_finish(&tcs); cpu_boost(false); return false; } @@ -2332,7 +2334,7 @@ static bool insert_all_playlist(struct tree_context *c, } } - if (playlist_insert_track(NULL, buf, position, queue, false) < 0) { + if (playlist_insert_context_add(&context, buf) < 0) { logf("playlist_insert_track failed"); exit_loop_now = true; break; @@ -2350,10 +2352,12 @@ static bool insert_all_playlist(struct tree_context *c, if (exit_loop_now) break; } + if (playlist == NULL) - playlist_sync(NULL); + playlist_insert_context_release(&context); else close(fd); + tagcache_search_finish(&tcs); cpu_boost(false);