From 2219e3ce75fe741357eec4afafb2baa7ca476673 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Tue, 11 Jun 2024 23:25:56 +0200 Subject: [PATCH] [scan] Fix bug where playlist name isn't updated when m3u/pls file is renamed Closes #1758 --- src/library/filescanner.c | 31 ++++++++++++++++++------------ src/library/filescanner.h | 7 ++++--- src/library/filescanner_playlist.c | 12 +++++++++++- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/library/filescanner.c b/src/library/filescanner.c index 54b6d257..2bb208b4 100644 --- a/src/library/filescanner.c +++ b/src/library/filescanner.c @@ -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; diff --git a/src/library/filescanner.h b/src/library/filescanner.h index 7000faa1..52370c1e 100644 --- a/src/library/filescanner.h +++ b/src/library/filescanner.h @@ -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. * diff --git a/src/library/filescanner_playlist.c b/src/library/filescanner_playlist.c index c23193dd..c77b2e3e 100644 --- a/src/library/filescanner_playlist.c +++ b/src/library/filescanner_playlist.c @@ -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),