Enlightenment CVS committal
Author : chaos
Project : e17
Module : apps/evfs
Dir : e17/apps/evfs/src/bin
Modified Files:
evfs_metadata.c evfs_metadata_db.c
Log Message:
* Metadata will now be extracted for files placed in 'groups'. I have yet to
decide the scan algorithm we'll use to decide which files/locations will be
'automatically' searched for metadata-containing files. Open to suggestions :)
===================================================================
RCS file: /cvs/e/e17/apps/evfs/src/bin/evfs_metadata.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -3 -r1.21 -r1.22
--- evfs_metadata.c 22 Jul 2006 13:12:57 -0000 1.21
+++ evfs_metadata.c 22 Jul 2006 16:12:46 -0000 1.22
@@ -40,6 +40,7 @@
static char* homedir;
static char metadata_file[PATH_MAX];
+static char metadata_db[PATH_MAX];
static Eet_File* _evfs_metadata_eet;
static sqlite3 *db;
@@ -318,6 +319,7 @@
}
snprintf(metadata_file, PATH_MAX,
"%s/.e/evfs/evfs_metadata.eet", homedir);
+ snprintf(metadata_db, PATH_MAX, "%s/.e/evfs/evfs_metadata.db",
homedir);
if (stat(metadata_file, &config_dir_stat)) {
printf("Making new metadata file..\n");
@@ -492,6 +494,7 @@
}
+
void evfs_metadata_group_header_file_remove(evfs_filereference* ref, char*
group)
{
char* file_path;
@@ -633,17 +636,56 @@
{
int pid;
- if (!(pid = fork())) {
- evfs_plugin* plugin;
- evfs_command* command;
-
- printf("Extract fork started: %s..\n", ref->path);
-
- command = NEW(evfs_command);
- command->file_command.files = calloc(1,
sizeof(evfs_filereference*));
- command->file_command.files[0] = ref;
- plugin = evfs_meta_plugin_get_for_type(evfs_server_get(),
"object/undefined");
-
(*EVFS_PLUGIN_META(plugin)->functions->evfs_file_meta_retrieve)(NULL,command);
+ /*At the moment, we only extract meta from posix folders*/
+ /*This may change, but we'll have to copy the file locally,
+ * so libextractor can have a shot at it*/
+ if (!strcmp(ref->plugin_uri,"file")) {
+
+ if (!(pid = fork())) {
+ evfs_plugin* plugin;
+ evfs_command* command;
+ Evas_List* meta_list;
+ int ret;
+ sqlite3* db;
+ int file;
+ Evas_List* l;
+ evfs_meta_obj* o;
+
+ ret = sqlite3_open(metadata_db, &db);
+ if( ret ){
+ fprintf(stderr, "Can't open metadata database:
%s\n", sqlite3_errmsg(db));
+ sqlite3_close(db);
+ return 0;
+ }
+
+ printf("Extract fork started: %s..\n", ref->path);
+
+ file = evfs_metadata_db_id_for_file(db,ref,1);
+
+ if (file) {
+ command = NEW(evfs_command);
+ command->file_command.files = calloc(1,
sizeof(evfs_filereference*));
+ command->file_command.files[0] = ref;
+ plugin =
evfs_meta_plugin_get_for_type(evfs_server_get(), "object/undefined");
+ meta_list =
(*EVFS_PLUGIN_META(plugin)->functions->evfs_file_meta_retrieve)(NULL,command);
+
+ for (l=meta_list;l;) {
+ o=l->data;
+
+ evfs_metadata_db_file_keyword_add(db,
file, o->key, o->value);
+
+ if (o->key) free(o->key);
+ if (o->value) free(o->value);
+ free(o);
+ l=l->next;
+ }
+ } else {
+ printf("metadata_extract_fork: could not insert
file to db\n");
+ }
+
+ sqlite3_close(db);
+ }
+
}
return 1;
===================================================================
RCS file: /cvs/e/e17/apps/evfs/src/bin/evfs_metadata_db.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- evfs_metadata_db.c 22 Jul 2006 05:43:37 -0000 1.3
+++ evfs_metadata_db.c 22 Jul 2006 16:12:46 -0000 1.4
@@ -3,6 +3,7 @@
#include <limits.h>
#include <sqlite3.h>
#include "evfs_metadata_db.h"
+#include "evfs.h"
/* TODO
@@ -98,7 +99,6 @@
{
int ret;
char* errMsg = 0;
- char query[1024];
printf("Performing upgrade from v.2 to v.3\n");
@@ -149,8 +149,6 @@
/*Check if we need to seed the DB*/
if (stat(metadata_db, &config_dir_stat)) {
- char* errMsg = 0;
-
ret = sqlite3_open(metadata_db, db);
if( ret ){
fprintf(stderr, "Can't open metadata database: %s\n",
sqlite3_errmsg(*db));
@@ -232,4 +230,67 @@
} else {
return EVFS_METADATA_DB_CONFIG_LATEST;
}
+}
+
+
+int evfs_metadata_db_id_for_file(sqlite3* db, evfs_filereference* ref, int
create)
+{
+ char* file_path;
+ char query[PATH_MAX];
+ int ret;
+ int file = 0;
+ char* errMsg = 0;
+ sqlite3_stmt *pStmt;
+
+
+ /*Build a path*/
+ file_path = evfs_filereference_to_string(ref);
+ printf("File path is: %s\n", file_path);
+
+
+ snprintf(query, sizeof(query), "select id from File where filename
='%s'", file_path);
+ ret = sqlite3_prepare(db, query,
+ -1, &pStmt, 0);
+
+ if (ret == SQLITE_OK) {
+ ret = sqlite3_step(pStmt);
+ if (ret == SQLITE_ROW) {
+ file = sqlite3_column_int(pStmt,0);
+ } else {
+ if (create) {
+ snprintf(query, sizeof(query), "insert into
File (filename) select '%s';", file_path);
+ ret = sqlite3_exec(db, query,
+ NULL, 0,&errMsg);
+
+ file = (int)sqlite3_last_insert_rowid(db);
+ } else {
+ file = 0;
+ }
+ }
+ } else {
+ printf("id_for_file: sqlite error\n");
+ file = 0;
+ }
+ sqlite3_reset(pStmt);
+ sqlite3_finalize(pStmt);
+
+ return file;
+}
+
+void evfs_metadata_db_file_keyword_add(sqlite3* db, int file, char* key, char*
value)
+{
+ char* file_path;
+ char query[512];
+ int ret;
+ char* errMsg = 0;
+
+ if (key&&value) {
+ snprintf(query,sizeof(query), "insert into FileMeta (File,
keyword, value) select %d, '%s', '%s';", file,key,value);
+ ret = sqlite3_exec(db,
+ query,
+ NULL, 0,&errMsg);
+ } else {
+ printf("db_file_keyword_add: key or value is null\n");
+ }
+
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs