Skip to content

Commit

Permalink
[scan] Fix bug where playlist name isn't updated when m3u/pls file is…
Browse files Browse the repository at this point in the history
… renamed

Closes #1758
  • Loading branch information
ejurgensen committed Jun 12, 2024
1 parent 3af04af commit 2219e3c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
31 changes: 19 additions & 12 deletions src/library/filescanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;

Expand Down
7 changes: 4 additions & 3 deletions src/library/filescanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
12 changes: 11 additions & 1 deletion src/library/filescanner_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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),
Expand Down

0 comments on commit 2219e3c

Please sign in to comment.