X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=blobdiff_plain;f=etc%2Fspotlight%2Fslmod_sparql.c;h=21e8d382876dbfeb4082a886f7eb58e4a9ad6bbf;hp=fd0f984560e7c95403b33001d7b820aeaea4a374;hb=371efee757ed56fd9e2f46b39fae625924d2cfc2;hpb=96afca89fe09964bedaefcd6fd65cdc03b073243 diff --git a/etc/spotlight/slmod_sparql.c b/etc/spotlight/slmod_sparql.c index fd0f9845..21e8d382 100644 --- a/etc/spotlight/slmod_sparql.c +++ b/etc/spotlight/slmod_sparql.c @@ -34,7 +34,9 @@ #define MAX_SL_RESULTS 20 static TrackerSparqlConnection *connection; +#if 0 static TrackerMinerManager *manager; +#endif static char *tracker_to_unix_path(const char *uri) { @@ -57,12 +59,13 @@ static int sl_mod_init(void *p) { EC_INIT; GError *error = NULL; - const char *msg = p; + AFPObj *obj = (AFPObj *)p; + const char *attributes; LOG(log_info, logtype_sl, "Initializing Spotlight module"); g_type_init(); - setenv("DBUS_SESSION_BUS_ADDRESS", "unix:path=/tmp/spotlight.ipc", 1); + setenv("DBUS_SESSION_BUS_ADDRESS", "unix:path=" _PATH_STATEDIR "/spotlight.ipc", 1); setenv("TRACKER_SPARQL_BACKEND", "bus", 1); #ifdef DEBUG @@ -73,7 +76,9 @@ static int sl_mod_init(void *p) become_root(); connection = tracker_sparql_connection_get(NULL, &error); +#if 0 /* this may hang, so disable it as we don't use the miner anyway */ manager = tracker_miner_manager_new_full(FALSE, &error); +#endif unbecome_root(); if (!connection) { @@ -83,11 +88,18 @@ static int sl_mod_init(void *p) EC_FAIL; } +#if 0 if (!manager) { LOG(log_error, logtype_sl, "Couldn't connect to Tracker miner"); g_clear_error(&error); EC_FAIL; } +#endif + + attributes = atalk_iniparser_getstring(obj->iniconfig, INISEC_GLOBAL, "spotlight attributes", NULL); + if (attributes) { + configure_spotlight_attributes(attributes); + } EC_CLEANUP: EC_EXIT; @@ -148,12 +160,14 @@ EC_CLEANUP: EC_EXIT; } -static int add_filemeta(sl_array_t *reqinfo, sl_array_t *fm_array, cnid_t id, const char *path) +static int add_filemeta(sl_array_t *reqinfo, sl_array_t *fm_array, cnid_t id, const char *path, const struct stat *sp) { EC_INIT; sl_array_t *meta; sl_nil_t nil = 0; int i, metacount; + uint64_t uint64; + sl_time_t sl_time; if ((metacount = talloc_array_length(reqinfo->dd_talloc_array)) == 0) { dalloc_add_copy(fm_array, &nil, sl_nil_t); @@ -165,12 +179,25 @@ static int add_filemeta(sl_array_t *reqinfo, sl_array_t *fm_array, cnid_t id, co meta = talloc_zero(fm_array, sl_array_t); for (i = 0; i < metacount; i++) { - if (STRCMP(reqinfo->dd_talloc_array[i], ==, "kMDItemDisplayName")) { + if (STRCMP(reqinfo->dd_talloc_array[i], ==, "kMDItemDisplayName") || + STRCMP(reqinfo->dd_talloc_array[i], ==, "kMDItemFSName")) { char *p, *name; if ((p = strrchr(path, '/'))) { name = dalloc_strdup(meta, p + 1); dalloc_add(meta, name, "char *"); } + } else if (STRCMP(reqinfo->dd_talloc_array[i], ==, "kMDItemFSSize")) { + uint64 = sp->st_size; + dalloc_add_copy(meta, &uint64, uint64_t); + } else if (STRCMP(reqinfo->dd_talloc_array[i], ==, "kMDItemFSOwnerUserID")) { + uint64 = sp->st_uid; + dalloc_add_copy(meta, &uint64, uint64_t); + } else if (STRCMP(reqinfo->dd_talloc_array[i], ==, "kMDItemFSOwnerGroupID")) { + uint64 = sp->st_gid; + dalloc_add_copy(meta, &uint64, uint64_t); + } else if (STRCMP(reqinfo->dd_talloc_array[i], ==, "kMDItemFSContentChangeDate")) { + sl_time.tv_sec = sp->st_mtime; + dalloc_add_copy(meta, &sl_time, sl_time_t); } else { dalloc_add_copy(meta, &nil, sl_nil_t); } @@ -223,6 +250,8 @@ static int sl_mod_fetch_result(void *p) /* Prepare FileMeta */ fm = talloc_zero(slq->slq_reply, sl_filemeta_t); fm_array = talloc_zero(fm, sl_array_t); + /* For some reason the list of results always starts with a nil entry */ + dalloc_add_copy(fm_array, &nil, sl_nil_t); dalloc_add(fm, fm_array, sl_array_t); LOG(log_debug, logtype_sl, "sl_mod_fetch_result: now interating Tracker results cursor"); @@ -235,11 +264,13 @@ static int sl_mod_fetch_result(void *p) if (!qres) break; +#if 0 if (firstmatch) { /* For some reason the list of results always starts with a nil entry */ dalloc_add_copy(fm_array, &nil, sl_nil_t); firstmatch = false; } +#endif become_root(); uri = tracker_sparql_cursor_get_string(slq->slq_tracker_cursor, 0, NULL); @@ -248,7 +279,7 @@ static int sl_mod_fetch_result(void *p) EC_NULL_LOG( path = tracker_to_unix_path(uri) ); if ((id = cnid_for_path(slq->slq_vol->v_cdb, slq->slq_vol->v_path, path, &did)) == CNID_INVALID) { - LOG(log_error, logtype_sl, "sl_mod_fetch_result: cnid_for_path error: %s", path); + LOG(log_debug, logtype_sl, "sl_mod_fetch_result: cnid_for_path error: %s", path); goto loop_cleanup; } LOG(log_debug, logtype_sl, "Result %d: CNID: %" PRIu32 ", path: \"%s\"", i, ntohl(id), path); @@ -259,8 +290,12 @@ static int sl_mod_fetch_result(void *p) goto loop_cleanup; } + struct stat sb; + if (stat(path, &sb) != 0) + goto loop_cleanup; + dalloc_add_copy(cnids->ca_cnids, &uint64, uint64_t); - add_filemeta(slq->slq_reqinfo, fm_array, id, path); + add_filemeta(slq->slq_reqinfo, fm_array, id, path, &sb); loop_cleanup: g_free(path); @@ -307,6 +342,35 @@ EC_CLEANUP: EC_EXIT; } +static int sl_mod_fetch_attrs(void *p) +{ + EC_INIT; + slq_t *slq = p; + sl_filemeta_t *fm; + sl_array_t *fm_array; + sl_nil_t nil; + + LOG(log_debug, logtype_sl, "sl_mod_fetch_attrs(\"%s\")", slq->slq_path); + + struct stat sb; + EC_ZERO( stat(slq->slq_path, &sb) ); + + /* Prepare FileMeta */ + fm = talloc_zero(slq->slq_reply, sl_filemeta_t); + fm_array = talloc_zero(fm, sl_array_t); + dalloc_add(fm, fm_array, fm_array_t); + /* For some reason the list of results always starts with a nil entry */ + dalloc_add_copy(fm_array, &nil, sl_nil_t); + + add_filemeta(slq->slq_reqinfo, fm_array, CNID_INVALID, slq->slq_path, &sb); + + /* Now add result */ + dalloc_add(slq->slq_reply, fm, sl_filemeta_t); + +EC_CLEANUP: + EC_EXIT; +} + static int sl_mod_error(void *p) { EC_INIT; @@ -326,6 +390,16 @@ EC_CLEANUP: static int sl_mod_index_file(const void *p) { + /* + * This seems to cause index problems on volumes that are watched and indexed + * by Tracker, so we disable this extra manual indexing for now. + * It's primary pupose was ensuring files created via AFP are indexed on large + * volumes where the filesystem event notification engine (eg FAM or FEN) may + * impose limits on the maximum number of watched directories. + */ + return 0; + +#if 0 #ifdef HAVE_TRACKER_MINER EC_INIT; const char *f = p; @@ -353,7 +427,8 @@ EC_CLEANUP: EC_EXIT; #else return 0; -#endif +#endif /* HAVE_TRACKER_MINER */ +#endif /* 0 */ } struct sl_module_export sl_mod = { @@ -362,6 +437,7 @@ struct sl_module_export sl_mod = { sl_mod_start_search, sl_mod_fetch_result, sl_mod_close_query, + sl_mod_fetch_attrs, sl_mod_error, sl_mod_index_file };