summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-09-02 22:47:30 +0200
committerKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-09-02 22:50:06 +0200
commit5f83ed096a8f0e19cd4658258c07630d17c4b488 (patch)
tree2719fa35c3841e8c4e8788a4f3f8961e0e1cbc93
parent03f4bf1cbe80d7e196b301c44e9ee0cc95529d69 (diff)
- Added active-flag to database (convenient when scanning paths)
- Disable active-flag on old directories
-rw-r--r--dbschema.sql1
-rw-r--r--src/mfs_subr.c33
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);