[scan] Fix bug where playlist name isn't updated when m3u/pls file is renamed

Closes #1758
This commit is contained in:
ejurgensen 2024-06-11 23:25:56 +02:00
parent 3af04afa61
commit 2219e3ce75
3 changed files with 34 additions and 16 deletions

View File

@ -166,6 +166,20 @@ filescanner_fullrescan();
/* ----------------------- Internal utility functions --------------------- */
static char *
strip_extension(const char *path)
{
char *ptr;
char *result;
result = strdup(path);
ptr = strrchr(result, '.');
if (ptr)
*ptr = '\0';
return result;
}
static int
virtual_path_make(char *virtual_path, int virtual_path_len, const char *path)
{
@ -388,17 +402,13 @@ filename_from_path(const char *path)
}
char *
strip_extension(const char *path)
title_from_path(const char *path)
{
char *ptr;
char *result;
const char *filename;
result = strdup(path);
ptr = strrchr(result, '.');
if (ptr)
*ptr = '\0';
filename = filename_from_path(path);
return result;
return strip_extension(filename);
}
int
@ -425,12 +435,9 @@ parent_dir(const char **current, const char *path)
int
playlist_fill(struct playlist_info *pli, const char *path)
{
const char *filename;
char virtual_path[PATH_MAX];
int ret;
filename = filename_from_path(path);
ret = virtual_path_make(virtual_path, sizeof(virtual_path), path);
if (ret < 0)
return -1;
@ -439,7 +446,7 @@ playlist_fill(struct playlist_info *pli, const char *path)
pli->type = PL_PLAIN;
pli->path = strdup(path);
pli->title = strip_extension(filename); // Will alloc
pli->title = title_from_path(path); // Will alloc
pli->virtual_path = strip_extension(virtual_path); // Will alloc
pli->scan_kind = SCAN_KIND_FILES;

View File

@ -33,13 +33,14 @@ scan_itunes_itml(const char *file, time_t mtime, int dir_id);
const char *
filename_from_path(const char *path);
/* Returns path without file extension. Caller must free result.
/* Sets a title (=filename without extension and path) from a path. Caller must
* free the result.
*
* @in path the complete path
* @return modified path
* @return allocated title
*/
char *
strip_extension(const char *path);
title_from_path(const char *path);
/* Iterate up a file path.
*

View File

@ -371,6 +371,7 @@ static int
playlist_prepare(const char *path, time_t mtime)
{
struct playlist_info *pli;
char *old_title;
int pl_id;
pli = db_pl_fetch_bypath(path);
@ -389,7 +390,16 @@ playlist_prepare(const char *path, time_t mtime)
return pl_id;
}
db_pl_ping(pli->id);
// So we already have the playlist, but maybe it has been renamed
old_title = pli->title;
pli->title = title_from_path(path);
if (strcasecmp(old_title, pli->title) != 0)
db_pl_update(pli);
else
db_pl_ping(pli->id);
free(old_title);
// mtime == db_timestamp is also treated as a modification because some editors do
// stuff like 1) close the file with no changes (leading us to update db_timestamp),