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 --- src/mfs_subr.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'src/mfs_subr.c') 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