diff options
-rw-r--r-- | include/musicfs.h | 4 | ||||
-rw-r--r-- | src/mfs_subr.c | 25 |
2 files changed, 25 insertions, 4 deletions
diff --git a/include/musicfs.h b/include/musicfs.h index b3f2ebe..21fd0b4 100644 --- a/include/musicfs.h +++ b/include/musicfs.h @@ -33,7 +33,7 @@ int mfs_initscan(char *); * files, for instance scanning the collection. */ typedef void traverse_fn_t(char *); -void traverse_hierarchy(char *, traverse_fn_t); +void traverse_hierarchy(const char *, traverse_fn_t); traverse_fn_t mfs_scan; /* @@ -65,6 +65,8 @@ lookup_fn_t mfs_lookup_list; lookup_fn_t mfs_lookup_open; /* Lookup function stat'ing a file. */ lookup_fn_t mfs_lookup_stat; +/* Lookup function loading a path into DB */ +lookup_fn_t mfs_lookup_load_path; struct lookuphandle; diff --git a/src/mfs_subr.c b/src/mfs_subr.c index b4dfde4..21cc5d6 100644 --- a/src/mfs_subr.c +++ b/src/mfs_subr.c @@ -130,6 +130,7 @@ mfs_reload_config() FILE *f = fopen(mfsrc, "r"); char line[4096]; sqlite3 *handle; + struct lookuphandle *lh; res = sqlite3_open(DBNAME, &handle); if (res) { @@ -151,8 +152,14 @@ mfs_reload_config() } } - sqlite3_close(handle); free (mfsrc); + + /* Do the actual loading */ + lh = mfs_lookup_start(0, handle, mfs_lookup_load_path, + "SELECT path FROM path"); + mfs_lookup_finish(lh); + + sqlite3_close(handle); return (0); } @@ -177,7 +184,6 @@ mfs_initscan(char *musicpath) if (error != 0) return (error); - traverse_hierarchy(musicpath, mfs_scan); sqlite3_close(handle); return (0); } @@ -188,8 +194,9 @@ mfs_initscan(char *musicpath) * sub-directories. */ void -traverse_hierarchy(char *dirpath, traverse_fn_t fileop) +traverse_hierarchy(const char *dirpath, traverse_fn_t fileop) { + DEBUG("traversing %s\n", dirpath); DIR *dirp; struct dirent *dp; char filepath[MAXPATHLEN]; @@ -850,6 +857,18 @@ mfs_lookup_stat(void *data, const char *str) } /* + * Load a path into database + */ +int +mfs_lookup_load_path(void *data, const char *str) +{ + handle = (sqlite3 *)data; + traverse_hierarchy(str, mfs_scan); + + return (1); +} + +/* * Guess on a filetype for a path. * * Examples: |