summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-09-07 18:19:03 +0200
committerKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-09-07 18:19:03 +0200
commit350b6c1d0b4c1859d4d1be64f3a520100948c122 (patch)
treecd2f0b913a86eaac19e75a9c33d8479fc3ed861c
parent640d85d2f8ec89fd2af857fd69ce19f0a636534c (diff)
- Moved mfs_cleanup_db code to its own file
-rw-r--r--include/mfs_cleanup_db.h29
-rw-r--r--src/mfs_cleanup_db.c96
-rw-r--r--src/mfs_subr.c73
3 files changed, 128 insertions, 70 deletions
diff --git a/include/mfs_cleanup_db.h b/include/mfs_cleanup_db.h
new file mode 100644
index 0000000..24e977a
--- /dev/null
+++ b/include/mfs_cleanup_db.h
@@ -0,0 +1,29 @@
+/*
+ * Musicfs is a FUSE module implementing a media filesystem in userland.
+ * Copyright (C) 2008 Ulf Lilleengen, Kjetil Ørbekk
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * A copy of the license can typically be found in COPYING
+ */
+
+#ifndef _MFS_CLEANUP_H_
+#define _MFS_CLEANUP_H_
+struct fuse_args;
+
+#include <sqlite3.h>
+
+void mfs_cleanup_db(sqlite3 *handle);
+
+#endif
diff --git a/src/mfs_cleanup_db.c b/src/mfs_cleanup_db.c
new file mode 100644
index 0000000..3ce2ff3
--- /dev/null
+++ b/src/mfs_cleanup_db.c
@@ -0,0 +1,96 @@
+/*
+ * Musicfs is a FUSE module implementing a media filesystem in userland.
+ * Copyright (C) 2008 Ulf Lilleengen, Kjetil Ørbekk
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * A copy of the license can typically be found in COPYING
+ */
+
+#include <sqlite3.h>
+#include <pthread.h>
+
+#include <debug.h>
+#include <musicfs.h>
+
+extern char *db_path;
+
+/*
+ * Clean up the database:
+ *
+ * - Remove disabled paths
+ * - Remove songs in disabled paths
+ * - Remove unused artists and genres
+ */
+void
+mfs_cleanup_db(sqlite3 *handle)
+{
+ DEBUG("cleaning up db\n");
+ /* sqlite doesn't support deleting from multiple tables at the same time :-( */
+ sqlite3_stmt *st, *st_;
+ int res, res_;
+ const char *path;
+
+
+ /* Removed songs from inactive paths */
+ res = sqlite3_prepare_v2(handle, "SELECT path FROM path WHERE "
+ "active = 0", -1, &st, NULL);
+ if (res != SQLITE_OK) {
+ DEBUG("Error preparing statement: %s\n",
+ sqlite3_errmsg(handle));
+ return;
+ }
+ res = sqlite3_step(st);
+
+ while (res == SQLITE_ROW) {
+ path = (const char*)sqlite3_column_text(st, 0);
+
+ res_ = sqlite3_prepare_v2(handle, "DELETE FROM song WHERE "
+ "filepath LIKE (?||'%')", -1, &st_, NULL);
+ if (res_ != SQLITE_OK) {
+ DEBUG("Error preparing statement: %s\n",
+ sqlite3_errmsg(handle));
+ return;
+ }
+
+ DEBUG("removing songs from '%s'\n", path);
+ sqlite3_bind_text(st_, 1, path, -1, SQLITE_TRANSIENT);
+ res_ = sqlite3_step(st_);
+ if (res_ != SQLITE_DONE) {
+ DEBUG("Error deleting '%s' from database: %s\n",
+ path, sqlite3_errmsg(handle));
+ }
+ sqlite3_finalize(st_);
+
+ res = sqlite3_step(st);
+ }
+ sqlite3_finalize(st);
+
+ /* Remove the actual paths */
+ res = sqlite3_prepare_v2(handle, "DELETE FROM path WHERE "
+ "active = 0", -1, &st, NULL);
+ if (res != SQLITE_OK) {
+ DEBUG("Error preparing statement: %s\n",
+ sqlite3_errmsg(handle));
+ return;
+ }
+ res = sqlite3_step(st);
+ if (res != SQLITE_DONE) {
+ DEBUG("Error deleting inactive paths from db: %s\n",
+ sqlite3_errmsg(handle));
+ return;
+ }
+ sqlite3_finalize(st);
+}
+
diff --git a/src/mfs_subr.c b/src/mfs_subr.c
index 4ddd81e..c669497 100644
--- a/src/mfs_subr.c
+++ b/src/mfs_subr.c
@@ -33,11 +33,12 @@
#include <dirent.h>
#include <fuse.h>
#include <pthread.h>
-
#include <tag_c.h>
+
+#include <debug.h>
#include <musicfs.h>
#include <sqlite3.h>
-#include <debug.h>
+#include <mfs_cleanup_db.h>
#define MFS_HANDLE ((void*)-1)
@@ -148,74 +149,6 @@ mfs_insert_path(const char *path, sqlite3 *handle)
}
/*
- * Clean up the database:
- *
- * - Remove disabled paths
- * - Remove songs in disabled paths
- * - Remove unused artists and genres
- */
-void
-mfs_cleanup_db(sqlite3 *handle)
-{
- DEBUG("cleaning up db\n");
- /* sqlite doesn't support deleting from multiple tables at the same time :-( */
- sqlite3_stmt *st, *st_;
- int res, res_;
- const char *path;
-
-
- /* Removed songs from inactive paths */
- res = sqlite3_prepare_v2(handle, "SELECT path FROM path WHERE "
- "active = 0", -1, &st, NULL);
- if (res != SQLITE_OK) {
- DEBUG("Error preparing statement: %s\n",
- sqlite3_errmsg(handle));
- return;
- }
- res = sqlite3_step(st);
-
- while (res == SQLITE_ROW) {
- path = (const char*)sqlite3_column_text(st, 0);
-
- res_ = sqlite3_prepare_v2(handle, "DELETE FROM song WHERE "
- "filepath LIKE (?||'%')", -1, &st_, NULL);
- if (res_ != SQLITE_OK) {
- DEBUG("Error preparing statement: %s\n",
- sqlite3_errmsg(handle));
- return;
- }
-
- DEBUG("removing songs from '%s'\n", path);
- sqlite3_bind_text(st_, 1, path, -1, SQLITE_TRANSIENT);
- res_ = sqlite3_step(st_);
- if (res_ != SQLITE_DONE) {
- DEBUG("Error deleting '%s' from database: %s\n",
- path, sqlite3_errmsg(handle));
- }
- sqlite3_finalize(st_);
-
- res = sqlite3_step(st);
- }
- sqlite3_finalize(st);
-
- /* Remove the actual paths */
- res = sqlite3_prepare_v2(handle, "DELETE FROM path WHERE "
- "active = 0", -1, &st, NULL);
- if (res != SQLITE_OK) {
- DEBUG("Error preparing statement: %s\n",
- sqlite3_errmsg(handle));
- return;
- }
- res = sqlite3_step(st);
- if (res != SQLITE_DONE) {
- DEBUG("Error deleting inactive paths from db: %s\n",
- sqlite3_errmsg(handle));
- return;
- }
- sqlite3_finalize(st);
-}
-
-/*
* Reload the configuration from $HOME/.mfsrc
*
*/