Merge pull request #1769 from owntone/fix_rename_pl1

[scan] Fix bug where playlist name isn't updated when m3u/pls file is…
This commit is contained in:
ejurgensen 2024-06-12 16:04:34 +02:00 committed by GitHub
commit bf73e51262
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 16 deletions

View File

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

View File

@ -371,6 +371,7 @@ static int
playlist_prepare(const char *path, time_t mtime) playlist_prepare(const char *path, time_t mtime)
{ {
struct playlist_info *pli; struct playlist_info *pli;
char *old_title;
int pl_id; int pl_id;
pli = db_pl_fetch_bypath(path); pli = db_pl_fetch_bypath(path);
@ -389,7 +390,16 @@ playlist_prepare(const char *path, time_t mtime)
return pl_id; 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 // 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), // stuff like 1) close the file with no changes (leading us to update db_timestamp),