Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* cleanup --exec implementation

  • Loading branch information...
commit 5441b1945fa63ad5407583a06cd519ce23f3e919 1 parent 76b946e
@djcb authored
Showing with 65 additions and 59 deletions.
  1. +1 −0  Makefile.am
  2. +38 −26 src/mu-cmd-find.c
  3. +26 −33 src/mu-store.cc
View
1  Makefile.am
@@ -53,6 +53,7 @@ cc10:
line33:
@$(PMCCABE) -c `find -name '*.c' -o -name '*.cc'` \
| grep -v mu-str-normalize.c \
+ | grep -v config_options_group_find \
| grep -v tests \
| awk '($$5 > 33)'
View
64 src/mu-cmd-find.c
@@ -215,6 +215,38 @@ process_query (MuQuery *xapian, const gchar *query, MuConfig *opts,
}
+static gboolean
+exec_cmd (const char *path, const char *cmd)
+{
+ gint status;
+ GError *err;
+ char *cmdline, *escpath;
+ gboolean rv;
+
+ if (access (path, R_OK) != 0) {
+ g_warning ("cannot read %s: %s", path, strerror(errno));
+ return FALSE;
+ }
+
+ escpath = g_strescape (path, NULL);
+
+ cmdline = g_strdup_printf ("%s %s", cmd, escpath);
+ err = NULL;
+ rv = g_spawn_command_line_sync (cmdline, NULL, NULL,
+ &status, &err);
+ g_free (cmdline);
+ g_free (escpath);
+
+ if (!rv) {
+ g_warning ("command returned %d on %s: %s\n",
+ status, path, err->message);
+ g_error_free (err);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static gboolean
exec_cmd_on_query (MuQuery *xapian, const gchar *query, MuConfig *opts,
@@ -223,34 +255,14 @@ exec_cmd_on_query (MuQuery *xapian, const gchar *query, MuConfig *opts,
MuMsgIter *iter;
gboolean rv;
- iter = run_query (xapian, query, opts, count);
- if (!iter)
+ if (!(iter = run_query (xapian, query, opts, count)))
return FALSE;
- rv = TRUE;
- while (!mu_msg_iter_is_done (iter)) {
- const char* path;
- path = mu_msg_get_path (mu_msg_iter_get_msg (iter, NULL));
- if (access (path, R_OK) == 0) {
- gint status;
- GError *err;
- char *cmd;
- cmd = g_strdup_printf ("%s %s", opts->exec, path);
- err = NULL; /* FIXME: stdout/stderr */
- rv = g_spawn_command_line_sync (cmd, NULL, NULL, &status,
- &err);
- g_free (cmd);
- if (!rv) {
- g_warning ("command returned %d on %s: %s\n",
- status, path, err->message);
- g_error_free (err);
- break;
- }
- } else
- g_warning ("cannot execute command on %s: %s",
- path, strerror(errno));
-
- mu_msg_iter_next (iter);
+ for (rv = TRUE, *count = 0; !mu_msg_iter_is_done (iter); mu_msg_iter_next(iter)) {
+ rv = exec_cmd (mu_msg_get_path (mu_msg_iter_get_msg (iter, NULL)),
+ opts->exec);
+ if (rv)
+ ++*count;
}
if (rv && count && *count == 0)
View
59 src/mu-store.cc
@@ -374,6 +374,30 @@ add_terms_values_str (Xapian::Document& doc, char *val,
doc.add_term (prefix(mfid) +
std::string(val, 0, MU_STORE_MAX_TERM_LENGTH));
}
+
+
+static void
+add_terms_values_string (Xapian::Document& doc, MuMsg *msg,
+ MuMsgFieldId mfid)
+{
+ const char *orig;
+ char *val;
+ size_t len;
+
+ if (!(orig = mu_msg_get_field_string (msg, mfid)))
+ return; /* nothing to do */
+
+ /* try stack-allocation, it's much faster*/
+ len = strlen (orig);
+ val = (char*)(G_LIKELY(len < 1024)?g_alloca(len+1):g_malloc(len+1));
+ strcpy (val, orig);
+
+ add_terms_values_str (doc, val, mfid);
+
+ if (!(G_LIKELY(len < 1024)))
+ g_free (val);
+}
+
static void
@@ -402,18 +426,10 @@ add_terms_values_string_list (Xapian::Document& doc, MuMsg *msg,
val = (char*)g_alloca(len+1);
else
val = (char*)g_malloc(len+1);
-
strcpy (val, (char*)lst->data);
-
- if (mu_msg_field_normalize (mfid))
- mu_str_normalize_in_place (val, TRUE);
-
- if (mu_msg_field_xapian_escape (mfid))
- mu_str_ascii_xapian_escape_in_place (val);
- doc.add_term (prefix(mfid) +
- std::string(val, 0, MU_STORE_MAX_TERM_LENGTH));
-
+ add_terms_values_str (doc, val, mfid);
+
if (!(G_LIKELY(len < 1024)))
g_free (val);
@@ -422,29 +438,6 @@ add_terms_values_string_list (Xapian::Document& doc, MuMsg *msg,
}
}
-
-
-static void
-add_terms_values_string (Xapian::Document& doc, MuMsg *msg,
- MuMsgFieldId mfid)
-{
- const char *orig;
- char *val;
- size_t len;
-
- if (!(orig = mu_msg_get_field_string (msg, mfid)))
- return; /* nothing to do */
-
- /* try stack-allocation, it's much faster*/
- len = strlen (orig);
- val = (char*)(G_LIKELY(len < 1024)?g_alloca(len+1):g_malloc(len+1));
- strcpy (val, orig);
-
- add_terms_values_str (doc, val, mfid);
-
- if (!(G_LIKELY(len < 1024)))
- g_free (val);
-}
struct PartData {
PartData (Xapian::Document& doc, MuMsgFieldId mfid):
Please sign in to comment.
Something went wrong with that request. Please try again.