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 */