[sushi] sushi-pdf-loader: switch from shell command parsing to a static argv
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sushi] sushi-pdf-loader: switch from shell command parsing to a static argv
- Date: Thu, 19 Apr 2018 01:38:31 +0000 (UTC)
commit 2b3e73565e89d87d77c641160d0960f9a4796b33
Author: Robert McQueen <rob endlessm com>
Date: Wed Apr 18 21:49:40 2018 +0100
sushi-pdf-loader: switch from shell command parsing to a static argv
Simplifies logic around quoting then parsing the same strings.
src/libsushi/sushi-pdf-loader.c | 44 ++++++++++++++++----------------------
1 files changed, 19 insertions(+), 25 deletions(-)
---
diff --git a/src/libsushi/sushi-pdf-loader.c b/src/libsushi/sushi-pdf-loader.c
index 8d41612..f688caa 100644
--- a/src/libsushi/sushi-pdf-loader.c
+++ b/src/libsushi/sushi-pdf-loader.c
@@ -156,16 +156,19 @@ unoconv_child_watch_cb (GPid pid,
static void
load_openoffice (SushiPdfLoader *self)
{
- gchar *doc_path, *pdf_path, *tmp_name, *tmp_path, *quoted_path;
+ gchar *unoconv_path;
GFile *file;
+ gchar *doc_path, *tmp_name, *tmp_path, *pdf_path;
gboolean res;
- gchar *cmd;
-
- gint argc;
GPid pid;
- gchar **argv = NULL;
GError *error = NULL;
- const gchar *unoconv_path;
+ const gchar *unoconv_argv[] = {
+ NULL /* to be replaced with binary */,
+ "-f", "pdf",
+ "-o", NULL /* to be replaced with output file */,
+ NULL /* to be replaced with input file */,
+ NULL
+ };
unoconv_path = g_find_program_in_path ("unoconv");
if (unoconv_path == NULL) {
@@ -175,10 +178,7 @@ load_openoffice (SushiPdfLoader *self)
file = g_file_new_for_uri (self->priv->uri);
doc_path = g_file_get_path (file);
- quoted_path = g_shell_quote (doc_path);
-
g_object_unref (file);
- g_free (doc_path);
tmp_name = g_strdup_printf ("sushi-%d.pdf", getpid ());
tmp_path = g_build_filename (g_get_user_cache_dir (), "sushi", NULL);
@@ -186,30 +186,24 @@ load_openoffice (SushiPdfLoader *self)
g_build_filename (tmp_path, tmp_name, NULL);
g_mkdir_with_parents (tmp_path, 0700);
- cmd = g_strdup_printf ("unoconv -f pdf -o %s %s", pdf_path, quoted_path);
-
g_free (tmp_name);
g_free (tmp_path);
- g_free (quoted_path);
-
- res = g_shell_parse_argv (cmd, &argc, &argv, &error);
- g_free (cmd);
- if (!res) {
- g_warning ("Error while parsing the unoconv command line: %s",
- error->message);
- g_error_free (error);
+ unoconv_argv[0] = unoconv_path;
+ unoconv_argv[4] = pdf_path;
+ unoconv_argv[5] = doc_path;
- return;
- }
+ tmp_name = g_strjoinv (" ", (gchar **) unoconv_argv);
+ g_debug ("Executing LibreOffice command: %s", tmp_name);
+ g_free (tmp_name);
- res = g_spawn_async (NULL, argv, NULL,
- G_SPAWN_DO_NOT_REAP_CHILD |
- G_SPAWN_SEARCH_PATH,
+ res = g_spawn_async (NULL, (gchar **) unoconv_argv, NULL,
+ G_SPAWN_DO_NOT_REAP_CHILD,
NULL, NULL,
&pid, &error);
- g_strfreev (argv);
+ g_free (doc_path);
+ g_free (unoconv_path);
if (!res) {
g_warning ("Error while spawning unoconv: %s",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]