]> arthur.barton.de Git - netatalk.git/commitdiff
Spotlight: Limiting searches to subfolders, bug #581
authorRalph Boehme <slow@samba.org>
Mon, 6 Oct 2014 14:05:22 +0000 (16:05 +0200)
committerRalph Boehme <slow@samba.org>
Mon, 6 Oct 2014 14:07:18 +0000 (16:07 +0200)
Netatalk didn't use the kMDScopeArray Spotlight query
attribute. Instead the volume path was passed to the SPARQL query
mapper.

Simple fix: pass the kMDScopeArray value instead of the volume path.

Signed-off-by: Ralph Boehme <slow@samba.org>
NEWS
etc/afpd/spotlight.c
etc/spotlight/sparql_parser.c
etc/spotlight/sparql_parser.y
include/atalk/spotlight.h

diff --git a/NEWS b/NEWS
index 3da15603643495eb5ae36c59bbd204f770bba5bf..9fad3d449ce638df80fa22decf699c423b617021 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Changes in 3.1.7
 * FIX: afpd: Solaris locking problem, bug #559
 * FIX: Handling of malformed UTF8 strings, bug #524
 * FIX: afpd: umask handling, bug #576
+* FIX: Spotlight: Limiting searches to subfolders, bug #581
 
 Changes in 3.1.6
 ================
index d2539b8358e25684e3d4c568ee8cce9df55c73ea..4aabeca91eb0904ad07d4ac29bae0c7389ad1658 100644 (file)
@@ -830,6 +830,7 @@ static int sl_rpc_openQuery(AFPObj *obj,
     gchar *sparql_query;
     GError *error = NULL;
     bool ok;
+    sl_array_t *scope_array;
 
     array = talloc_zero(reply, sl_array_t);
 
@@ -887,6 +888,20 @@ static int sl_rpc_openQuery(AFPObj *obj,
     }
     slq->slq_reqinfo = talloc_steal(slq, reqinfo);
 
+    scope_array = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1,
+                                       "kMDScopeArray");
+    if (scope_array == NULL) {
+        slq->slq_scope = talloc_strdup(slq, v->v_path);
+    } else {
+        slq->slq_scope = talloc_strdup(slq, scope_array->dd_talloc_array[0]);
+    }
+    if (slq->slq_scope == NULL) {
+        LOG(log_error, logtype_sl, "failed to setup search scope");
+        EC_FAIL;
+    }
+
+    LOG(log_debug, logtype_sl, "Search scope: \"%s\"", slq->slq_scope);
+
     cnids = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1,
                                  "kMDQueryItemArray");
     if (cnids) {
index 77fa9e50ee512bccc10c13691bf4aa8246f095da..d6f5d3be7e6242e9ab7c0dbedb41291b9282631e 100644 (file)
@@ -1456,7 +1456,7 @@ yyreduce:
     ssp_result = talloc_asprintf(ssp_slq,
                                  "SELECT ?url WHERE "
                                  "{ %s . ?obj nie:url ?url . FILTER(tracker:uri-is-descendant('file://%s/', ?url)) } %s",
-                                 (yyvsp[(1) - (1)].sval), ssp_slq->slq_vol->v_path, result_limit);
+                                 (yyvsp[(1) - (1)].sval), ssp_slq->slq_scope, result_limit);
     (yyval.sval) = ssp_result;
 }
     break;
@@ -2042,9 +2042,7 @@ int main(int argc, char **argv)
     }
 
     ssp_slq = talloc_zero(NULL, slq_t);
-    struct vol *vol = talloc_zero(ssp_slq, struct vol);
-    vol->v_path = "/Volumes/test";
-    ssp_slq->slq_vol = vol;
+    ssp_slq->slq_scope = talloc_strdup(ssp_slq, "/Volumes/test");
     ssp_slq->slq_allow_expr = true;
     sparqlvar = 'a';
 
index ede21872a725c47cdeacd87829088d810c176580..9d609976638c4898f8e521b7b5dd3af159694e86 100644 (file)
@@ -79,7 +79,7 @@ expr                           {
     ssp_result = talloc_asprintf(ssp_slq,
                                  "SELECT ?url WHERE "
                                  "{ %s . ?obj nie:url ?url . FILTER(tracker:uri-is-descendant('file://%s/', ?url)) } %s",
-                                 $1, ssp_slq->slq_vol->v_path, result_limit);
+                                 $1, ssp_slq->slq_scope, result_limit);
     $$ = ssp_result;
 }
 ;
@@ -352,9 +352,7 @@ int main(int argc, char **argv)
     }
 
     ssp_slq = talloc_zero(NULL, slq_t);
-    struct vol *vol = talloc_zero(ssp_slq, struct vol);
-    vol->v_path = "/Volumes/test";
-    ssp_slq->slq_vol = vol;
+    ssp_slq->slq_scope = talloc_strdup(ssp_slq, "/Volumes/test");
     ssp_slq->slq_allow_expr = true;
     sparqlvar = 'a';
 
index 395b9eadb434f2c93d98a27087f3b26980cf9ed5..0e64b8601c6866d8763a5dbd8820f2575f4202a3 100644 (file)
@@ -91,6 +91,7 @@ typedef struct _slq_t {
     slq_state_t       slq_state;          /* State                            */
     AFPObj           *slq_obj;            /* global AFPObj handle             */
     const struct vol *slq_vol;            /* volume handle                    */
+    char             *slq_scope;          /* search scope                     */
     time_t            slq_time;           /* timestamp received query         */
     uint64_t          slq_ctx1;           /* client context 1                 */
     uint64_t          slq_ctx2;           /* client context 2                 */