From 5f83ed096a8f0e19cd4658258c07630d17c4b488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Tue, 2 Sep 2008 22:47:30 +0200 Subject: - Added active-flag to database (convenient when scanning paths) - Disable active-flag on old directories --- dbschema.sql | 1 + src/mfs_subr.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/dbschema.sql b/dbschema.sql index 6d730d9..9a8c0c9 100644 --- a/dbschema.sql +++ b/dbschema.sql @@ -26,5 +26,6 @@ CREATE TABLE genre ( CREATE TABLE path ( path varchar(255), + active integer NOT NULL, PRIMARY KEY(path) ); diff --git a/src/mfs_subr.c b/src/mfs_subr.c index 0294a06..17a2126 100644 --- a/src/mfs_subr.c +++ b/src/mfs_subr.c @@ -101,7 +101,7 @@ mfs_insert_path(const char *path, sqlite3 *handle) DEBUG("Inserting path '%s' to paths\n", path); /* Doesn't exist. Insert it */ res = sqlite3_prepare_v2(handle, - "INSERT INTO path(path) VALUES(?)", + "INSERT INTO path(path, active) VALUES(?,1)", -1, &st, NULL); if (res != SQLITE_OK) { DEBUG("Error preparing stamtement: %s\n", @@ -117,6 +117,22 @@ mfs_insert_path(const char *path, sqlite3 *handle) return (-1); } } + else { + /* Path already in database, just activate it */ + res = sqlite3_prepare_v2(handle, "UPDATE path SET active = 1 " + "WHERE path LIKE ?", -1, &st, NULL); + if (res != SQLITE_OK) { + DEBUG("Error preparing statement: %s\n", + sqlite3_errmsg(handle)); + return (-1); + } + sqlite3_bind_text(st, 1, path, -1, SQLITE_TRANSIENT); + res = sqlite3_step(st); + sqlite3_finalize(st); + if (res != SQLITE_DONE) { + DEBUG("Error activating path '%s'\n", path); + } + } return (0); } @@ -132,6 +148,7 @@ mfs_reload_config() char line[4096]; struct lookuphandle *lh; sqlite3 *handle; + sqlite3_stmt *st; FILE *f = fopen(mfsrc, "r"); if (f == NULL) { @@ -147,7 +164,19 @@ mfs_reload_config() return (-1); } - /* XXX: Just adding the paths for now. queue.h for the rest*/ + /* Deactivate all paths */ + res = sqlite3_prepare_v2(handle, "UPDATE path SET active = 0", + -1, &st, NULL); + if (res != SQLITE_OK) { + DEBUG("Error preparing statement: %s\n", + sqlite3_errmsg(handle)); + return (-1); + } + res = sqlite3_step(st); + sqlite3_finalize(st); + if (res != SQLITE_DONE) { + DEBUG("Error deactivating paths.\n"); + } while (fgets(line, 4096, f) != NULL) { len = strlen(line); -- cgit v1.2.3