From 491bf54fdbc63906ef96ab2294063ff03ffe9eec Mon Sep 17 00:00:00 2001 From: chme Date: Sat, 30 Jan 2016 07:27:20 +0100 Subject: [PATCH] [directories/spotify] Init db with disabled spotify-root-directory and enable only on successful login to spotify --- src/db.c | 21 +++++++++++++++++++-- src/db.h | 3 +++ src/db_upgrade.c | 2 +- src/spotify.c | 2 ++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/db.c b/src/db.c index cf8a321c..8d84d7f8 100644 --- a/src/db.c +++ b/src/db.c @@ -3784,6 +3784,21 @@ db_directory_enable_bycookie(uint32_t cookie, char *path) #undef Q_TMPL } +int +db_directory_enable_bypath(char *path) +{ +#define Q_TMPL "UPDATE directories SET disabled = 0 WHERE virtual_path = %Q;" + char *query; + int ret; + + query = sqlite3_mprintf(Q_TMPL, path); + + ret = db_query_run(query, 1, 0); + + return ((ret < 0) ? -1 : sqlite3_changes(hdl)); +#undef Q_TMPL +} + /* Remotes */ static int @@ -3873,11 +3888,13 @@ db_pairing_fetch_byguid(struct pairing_info *pi) void db_spotify_purge(void) { - char *queries[3] = + char *queries[5] = { "DELETE FROM files WHERE path LIKE 'spotify:%%';", "DELETE FROM playlistitems WHERE filepath LIKE 'spotify:%%';", "DELETE FROM playlists WHERE path LIKE 'spotify:%%';", + "DELETE FROM directories WHERE virtual_path LIKE '/spotify:/%%';", + "UPDATE directories SET disabled = 4294967296 WHERE virtual_path = '/spotify:';", }; int i; int ret; @@ -4975,7 +4992,7 @@ db_perthread_deinit(void) " VALUES (3, '/http:', 0, 0, 1);" #define Q_DIR4 \ "INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \ - " VALUES (4, '/spotify:', 0, 0, 1);" + " VALUES (4, '/spotify:', 0, 4294967296, 1);" /* Rule of thumb: Will the current version of forked-daapd work with the new * version of the database? If yes, then it is a minor upgrade, if no, then it diff --git a/src/db.h b/src/db.h index 1429c781..23ad96fa 100644 --- a/src/db.h +++ b/src/db.h @@ -598,6 +598,9 @@ db_directory_disable_bymatch(char *path, char *strip, uint32_t cookie); int db_directory_enable_bycookie(uint32_t cookie, char *path); +int +db_directory_enable_bypath(char *path); + /* Remotes */ int db_pairing_add(struct pairing_info *pi); diff --git a/src/db_upgrade.c b/src/db_upgrade.c index b0d5c8f7..f3b3b2fe 100644 --- a/src/db_upgrade.c +++ b/src/db_upgrade.c @@ -1202,7 +1202,7 @@ static const struct db_upgrade_query db_upgrade_v1801_queries[] = " VALUES (3, '/http:', 0, 0, 1);" #define U_V1900_INSERT_DIR4 \ "INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \ - " VALUES (4, '/spotify:', 0, 0, 1);" + " VALUES (4, '/spotify:', 0, 4294967296, 1);" #define U_V1900_SCVER_MAJOR \ "UPDATE admin SET value = '19' WHERE key = 'schema_version_major';" diff --git a/src/spotify.c b/src/spotify.c index 1334e1f4..63be5efd 100644 --- a/src/spotify.c +++ b/src/spotify.c @@ -1417,6 +1417,8 @@ logged_in(sp_session *sess, sp_error error) DPRINTF(E_LOG, L_SPOTIFY, "Login to Spotify succeeded. Reloading playlists.\n"); + db_directory_enable_bypath("/spotify:"); + pl = fptr_sp_session_starred_create(sess); fptr_sp_playlist_add_callbacks(pl, &pl_callbacks, NULL);