1
0
Fork 0
forked from len0rd/rockbox

playlist save: ensure required file exists, proper filename used

Trying to save a current playlist associated with a
file that doesn't exist anymore, is likely to result
in a panic.

+return to keyboard picker after
complaining about missing dir.

Change-Id: I00ea0b08521d4a4503243d636af01252119939bc
This commit is contained in:
Christian Soffke 2025-03-11 17:57:27 +01:00
parent 8d2226f952
commit a77cb9dc77
3 changed files with 29 additions and 20 deletions

View file

@ -40,7 +40,6 @@
#include "splash.h"
#include "general.h"
#include "pathfuncs.h"
#include "dir.h"
/* load a screen to save the playlist passed in (or current playlist if NULL is passed) */
int save_playlist_screen(struct playlist_info* playlist)
@ -74,8 +73,7 @@ int save_playlist_screen(struct playlist_info* playlist)
if (len <= 1) /* root or dynamic playlist */
create_numbered_filename(temp, directoryonly, PLAYLIST_UNTITLED_PREFIX, ".m3u8",
1 IF_CNFN_NUM_(, NULL));
else if (temp[len - 1] == PATH_SEPCH /* dir playlists other than root */
&& temp[len] == '\0')
else if (temp[len - 1] == PATH_SEPCH) /* dir playlists other than root */
{
temp[len - 1] = '\0';
@ -89,24 +87,19 @@ int save_playlist_screen(struct playlist_info* playlist)
create_numbered_filename(temp, directoryonly, PLAYLIST_UNTITLED_PREFIX, ".m3u8",
1 IF_CNFN_NUM_(, NULL));
}
else if (!playlist) /* current playlist loaded from a playlist file */
{
if (!file_exists(temp))
{
splashf(HZ*2, ID2P(LANG_CATALOG_NO_DIRECTORY), temp);
return 0;
}
}
if (catalog_pick_new_playlist_name(temp, sizeof(temp),
playlist ? playlist->filename :
playlist_get_current()->filename))
{
/* Create dir if necessary */
if ((p = strrchr(temp, PATH_SEPCH)) && p != (char *) temp)
{
*p = '\0';
if (!dir_exists(temp) && mkdir(temp) < 0)
{
splashf(HZ, ID2P(LANG_CATALOG_NO_DIRECTORY), temp);
return 0;
}
*p = PATH_SEPCH;
}
playlist_save(playlist, temp);
/* reload in case playlist was saved to cwd */

View file

@ -411,16 +411,33 @@ static int remove_extension(char* path)
bool catalog_pick_new_playlist_name(char *pl_name, size_t buf_size,
const char* curr_pl_name)
{
char bmark_file[MAX_PATH + 7];
char bmark_file[MAX_PATH + 7], *p;
bool do_save = false;
while (!do_save && !remove_extension(pl_name) &&
!kbd_input(pl_name, buf_size - 7, NULL))
{
do_save = true;
if (*pl_name == PATH_SEPCH) /* Require absolute filenames */
{
p = strrchr(pl_name, PATH_SEPCH);
do_save = *(p + 1); /* Disallow empty filename */
/* prevent illegal characters */
fix_path_part(p, 1, strlen(p + 1));
/* Create dir if necessary */
if (do_save && p != (char *) pl_name)
{
*p = '\0';
do_save = dir_exists(pl_name) || mkdir(pl_name) == 0;
if (!do_save)
splashf(HZ*2, ID2P(LANG_CATALOG_NO_DIRECTORY), pl_name);
*p = PATH_SEPCH;
}
}
apply_playlist_extension(pl_name, buf_size);
/* warn before overwriting existing (different) playlist */
if (!curr_pl_name || strcmp(curr_pl_name, pl_name))
if (do_save && (!curr_pl_name || strcmp(curr_pl_name, pl_name)))
{
if (file_exists(pl_name))
do_save = yesno_pop(ID2P(LANG_REALLY_OVERWRITE));

View file

@ -172,7 +172,6 @@ The details of this menu are covered in
specified file. Asks for confirmation whether to remove queued tracks
from the current playlist, so that bookmarks can be created
(see \reference{ref:createbookmark}).
If no path is provided, playlist is saved to the root directory.
\item[Create Playlist:]
Rockbox will create a playlist with all tracks from the directory that is