From 7cd96690c05da5b1019288c1d8bd9d1452428760 Mon Sep 17 00:00:00 2001 From: chme Date: Sun, 31 May 2015 09:57:07 +0200 Subject: [PATCH] Remove file extension for playlists from virtual_path during scan and update db to v19 removing the file extensions from the stored playlists An existing file extension in the virtual path leads to wrong entries in MPDroid (and mpd does also not return the file extension). --- src/db.c | 37 +++++++++++++++++++++++++++++++++++-- src/filescanner_playlist.c | 3 +++ src/filescanner_smartpl.c | 4 ++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/db.c b/src/db.c index 025da845..fff76052 100644 --- a/src/db.c +++ b/src/db.c @@ -4639,10 +4639,10 @@ db_perthread_deinit(void) " VALUES(8, 'Purchased', 0, 'media_kind = 1024', 0, '', 0, 8);" */ -#define SCHEMA_VERSION_MAJOR 18 +#define SCHEMA_VERSION_MAJOR 19 #define SCHEMA_VERSION_MINOR 00 #define Q_SCVER_MAJOR \ - "INSERT INTO admin (key, value) VALUES ('schema_version_major', '18');" + "INSERT INTO admin (key, value) VALUES ('schema_version_major', '19');" #define Q_SCVER_MINOR \ "INSERT INTO admin (key, value) VALUES ('schema_version_minor', '00');" @@ -5900,6 +5900,32 @@ static const struct db_init_query db_upgrade_v18_queries[] = { U_V18_SCVER_MINOR, "set schema_version_minor to 00" }, }; +/* Upgrade from schema v18.00 to v19.00 */ +/* Change virtual_path for playlists: remove file extension + */ + +#define U_V19_UPDATE_PLAYLISTS_M3U \ + "UPDATE playlists SET virtual_path = replace(virtual_path, '.m3u', '');" +#define U_V19_UPDATE_PLAYLISTS_PLS \ + "UPDATE playlists SET virtual_path = replace(virtual_path, '.pls', '');" +#define U_V19_UPDATE_PLAYLISTS_SMARTPL \ + "UPDATE playlists SET virtual_path = replace(virtual_path, '.smartpl', '');" + +#define U_V19_SCVER_MAJOR \ + "UPDATE admin SET value = '19' WHERE key = 'schema_version_major';" +#define U_V19_SCVER_MINOR \ + "UPDATE admin SET value = '00' WHERE key = 'schema_version_minor';" + +static const struct db_init_query db_upgrade_v19_queries[] = + { + { U_V19_UPDATE_PLAYLISTS_M3U, "update table playlists" }, + { U_V19_UPDATE_PLAYLISTS_PLS, "update table playlists" }, + { U_V19_UPDATE_PLAYLISTS_SMARTPL, "update table playlists" }, + + { U_V19_SCVER_MAJOR, "set schema_version_major to 19" }, + { U_V19_SCVER_MINOR, "set schema_version_minor to 00" }, + }; + static int db_upgrade(int db_ver) { @@ -5992,6 +6018,13 @@ db_upgrade(int db_ver) if (ret < 0) return -1; + /* FALLTHROUGH */ + + case 1800: + ret = db_generic_upgrade(db_upgrade_v19_queries, sizeof(db_upgrade_v19_queries) / sizeof(db_upgrade_v19_queries[0])); + if (ret < 0) + return -1; + break; default: diff --git a/src/filescanner_playlist.c b/src/filescanner_playlist.c index 78efb9dc..605cc3c6 100644 --- a/src/filescanner_playlist.c +++ b/src/filescanner_playlist.c @@ -167,6 +167,9 @@ scan_playlist(char *file, time_t mtime) pli->path = strdup(file); snprintf(virtual_path, PATH_MAX, "/file:%s", file); + ptr = strrchr(virtual_path, '.'); + if (ptr) + *ptr = '\0'; pli->virtual_path = strdup(virtual_path); ret = db_pl_add(pli, &pl_id); diff --git a/src/filescanner_smartpl.c b/src/filescanner_smartpl.c index a183f1e5..f359b119 100644 --- a/src/filescanner_smartpl.c +++ b/src/filescanner_smartpl.c @@ -165,6 +165,7 @@ scan_smartpl(char *file, time_t mtime) struct playlist_info *pli; int pl_id; char virtual_path[PATH_MAX]; + char *ptr; int ret; /* Fetch or create playlist */ @@ -182,6 +183,9 @@ scan_smartpl(char *file, time_t mtime) pli->path = strdup(file); snprintf(virtual_path, PATH_MAX, "/file:%s", file); + ptr = strrchr(virtual_path, '.'); + if (ptr) + *ptr = '\0'; pli->virtual_path = strdup(virtual_path); pli->type = PL_SMART; }