diff --git a/Makefile-libostree.am b/Makefile-libostree.am index adcddf77..20af32cf 100644 --- a/Makefile-libostree.am +++ b/Makefile-libostree.am @@ -30,8 +30,6 @@ libostree_la_SOURCES = src/libostree/ostree.h \ src/libostree/ostree-repo-file.h \ src/libostree/ostree-repo-file-enumerator.c \ src/libostree/ostree-repo-file-enumerator.h \ - src/libostree/ostree-checkout.c \ - src/libostree/ostree-checkout.h \ $(NULL) if USE_LIBARCHIVE libostree_la_SOURCES += src/libostree/ostree-libarchive-input-stream.h \ diff --git a/Makefile-ostree.am b/Makefile-ostree.am index 8c8f8a2f..4d10bc22 100644 --- a/Makefile-ostree.am +++ b/Makefile-ostree.am @@ -31,7 +31,6 @@ ostree_SOURCES = src/ostree/main.c \ src/ostree/ot-builtin-local-clone.c \ src/ostree/ot-builtin-log.c \ src/ostree/ot-builtin-ls.c \ - src/ostree/ot-builtin-run-triggers.c \ src/ostree/ot-builtin-remote.c \ src/ostree/ot-builtin-rev-parse.c \ src/ostree/ot-builtin-show.c \ diff --git a/Makefile-triggers.am b/Makefile-triggers.am index 96beff0d..83af6ce7 100644 --- a/Makefile-triggers.am +++ b/Makefile-triggers.am @@ -19,12 +19,18 @@ triggersdir = $(libexecdir)/ostree/triggers.d triggers_SCRIPTS = \ - triggers.d/desktop-database.trigger \ - triggers.d/gdk-pixbuf.trigger \ - triggers.d/glib.trigger \ - triggers.d/gtk+.trigger \ - triggers.d/immodules.trigger \ - triggers.d/ldconfig.trigger \ - triggers.d/mime-database.trigger \ - triggers.d/pango.trigger \ + src/triggers/triggers.d/desktop-database.trigger \ + src/triggers/triggers.d/gdk-pixbuf.trigger \ + src/triggers/triggers.d/glib.trigger \ + src/triggers/triggers.d/gtk+.trigger \ + src/triggers/triggers.d/immodules.trigger \ + src/triggers/triggers.d/ldconfig.trigger \ + src/triggers/triggers.d/mime-database.trigger \ + src/triggers/triggers.d/pango.trigger \ $(NULL) + +bin_PROGRAMS += ostree-run-triggers + +ostree_run_triggers_SOURCES = src/triggers/ostree-run-triggers.c +ostree_run_triggers_CFLAGS = $(OT_DEP_GIO_UNIX_CFLAGS) +ostree_run_triggers_LDFLAGS = $(OT_DEP_GIO_UNIX_LIBS) diff --git a/src/libostree/ostree-checkout.c b/src/libostree/ostree-checkout.c deleted file mode 100644 index c4977ac2..00000000 --- a/src/libostree/ostree-checkout.c +++ /dev/null @@ -1,361 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- - * - * Copyright (C) 2011 Colin Walters - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Colin Walters - */ - -#include "config.h" - -#include "ostree.h" -#include "otutil.h" - -enum { - PROP_0, - - PROP_REPO, - PROP_PATH -}; - -G_DEFINE_TYPE (OstreeCheckout, ostree_checkout, G_TYPE_OBJECT) - -#define GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), OSTREE_TYPE_CHECKOUT, OstreeCheckoutPrivate)) - -typedef struct _OstreeCheckoutPrivate OstreeCheckoutPrivate; - -struct _OstreeCheckoutPrivate { - OstreeRepo *repo; - char *path; -}; - -static void -ostree_checkout_finalize (GObject *object) -{ - OstreeCheckout *self = OSTREE_CHECKOUT (object); - OstreeCheckoutPrivate *priv = GET_PRIVATE (self); - - g_free (priv->path); - g_clear_object (&priv->repo); - - G_OBJECT_CLASS (ostree_checkout_parent_class)->finalize (object); -} - -static void -ostree_checkout_set_property(GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - OstreeCheckout *self = OSTREE_CHECKOUT (object); - OstreeCheckoutPrivate *priv = GET_PRIVATE (self); - - switch (prop_id) - { - case PROP_PATH: - priv->path = g_value_dup_string (value); - break; - case PROP_REPO: - priv->repo = g_value_dup_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -ostree_checkout_get_property(GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - OstreeCheckout *self = OSTREE_CHECKOUT (object); - OstreeCheckoutPrivate *priv = GET_PRIVATE (self); - - switch (prop_id) - { - case PROP_PATH: - g_value_set_string (value, priv->path); - break; - case PROP_REPO: - g_value_set_object (value, priv->repo); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -ostree_checkout_constructor (GType gtype, - guint n_properties, - GObjectConstructParam *properties) -{ - GObject *object; - GObjectClass *parent_class; - OstreeCheckoutPrivate *priv; - - parent_class = G_OBJECT_CLASS (ostree_checkout_parent_class); - object = parent_class->constructor (gtype, n_properties, properties); - - priv = GET_PRIVATE (object); - - g_assert (priv->path != NULL); - - return object; -} - -static void -ostree_checkout_class_init (OstreeCheckoutClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (OstreeCheckoutPrivate)); - - object_class->constructor = ostree_checkout_constructor; - object_class->get_property = ostree_checkout_get_property; - object_class->set_property = ostree_checkout_set_property; - object_class->finalize = ostree_checkout_finalize; - - g_object_class_install_property (object_class, - PROP_PATH, - g_param_spec_string ("path", "", "", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, - PROP_REPO, - g_param_spec_object ("repo", "", "", - OSTREE_TYPE_REPO, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); -} - -static void -ostree_checkout_init (OstreeCheckout *self) -{ -} - -OstreeCheckout* -ostree_checkout_new (OstreeRepo *repo, - const char *path) -{ - return g_object_new (OSTREE_TYPE_CHECKOUT, "repo", repo, "path", path, NULL); -} - -static gboolean -executable_exists_in_checkout (const char *path, - const char *executable) -{ - int i; - const char *subdirs[] = {"bin", "sbin", "usr/bin", "usr/sbin"}; - - for (i = 0; i < G_N_ELEMENTS (subdirs); i++) - { - char *possible_path = g_build_filename (path, subdirs[i], executable, NULL); - gboolean exists; - - exists = g_file_test (possible_path, G_FILE_TEST_EXISTS); - g_free (possible_path); - - if (exists) - return TRUE; - } - - return FALSE; -} - -static gboolean -run_trigger (OstreeCheckout *self, - GFile *trigger, - gboolean requires_chroot, - GError **error) -{ - OstreeCheckoutPrivate *priv = GET_PRIVATE (self); - gboolean ret = FALSE; - const char *path = NULL; - char *temp_path = NULL; - char *rel_temp_path = NULL; - GFile *temp_copy = NULL; - char *basename = NULL; - GPtrArray *args = NULL; - int estatus; - - path = ot_gfile_get_path_cached (trigger); - basename = g_path_get_basename (path); - - args = g_ptr_array_new (); - - if (requires_chroot) - { - temp_path = g_build_filename (priv->path, basename, NULL); - rel_temp_path = g_strconcat ("./", basename, NULL); - temp_copy = ot_gfile_new_for_path (temp_path); - - if (!g_file_copy (trigger, temp_copy, 0, NULL, NULL, NULL, error)) - goto out; - - g_ptr_array_add (args, "chroot"); - g_ptr_array_add (args, "."); - g_ptr_array_add (args, rel_temp_path); - g_ptr_array_add (args, NULL); - } - else - { - g_ptr_array_add (args, (char*)path); - g_ptr_array_add (args, NULL); - } - - g_print ("Running trigger: %s\n", path); - if (!g_spawn_sync (priv->path, - (char**)args->pdata, - NULL, - G_SPAWN_SEARCH_PATH, - NULL, NULL, NULL, NULL, - &estatus, - error)) - { - g_prefix_error (error, "Failed to run trigger %s: ", basename); - goto out; - } - - ret = TRUE; - out: - if (requires_chroot && temp_path) - (void)unlink (temp_path); - - g_free (basename); - g_free (temp_path); - g_free (rel_temp_path); - g_clear_object (&temp_copy); - if (args) - g_ptr_array_free (args, TRUE); - return ret; -} - -static gboolean -check_trigger (OstreeCheckout *self, - GFile *trigger, - GError **error) -{ - OstreeCheckoutPrivate *priv = GET_PRIVATE (self); - gboolean ret = FALSE; - GInputStream *instream = NULL; - GDataInputStream *datain = NULL; - GError *temp_error = NULL; - char *line; - gsize len; - gboolean requires_chroot = TRUE; - gboolean matches = FALSE; - - instream = (GInputStream*)g_file_read (trigger, NULL, error); - if (!instream) - goto out; - datain = g_data_input_stream_new (instream); - - while ((line = g_data_input_stream_read_line (datain, &len, NULL, &temp_error)) != NULL) - { - if (g_str_has_prefix (line, "# IfExecutable: ")) - { - char *executable = g_strdup (line + strlen ("# IfExecutable: ")); - g_strchomp (executable); - matches = executable_exists_in_checkout (priv->path, executable); - g_free (executable); - } - - g_free (line); - } - if (line == NULL && temp_error != NULL) - { - g_propagate_error (error, temp_error); - goto out; - } - if (matches) - { - if (!run_trigger (self, trigger, requires_chroot, error)) - goto out; - } - - ret = TRUE; - out: - g_clear_object (&instream); - g_clear_object (&datain); - return ret; -} - -gboolean -ostree_checkout_run_triggers (OstreeCheckout *self, - GError **error) -{ - gboolean ret = FALSE; - GError *temp_error = NULL; - char *triggerdir_path = NULL; - GFile *triggerdir = NULL; - GFileInfo *file_info = NULL; - GFileEnumerator *enumerator = NULL; - - triggerdir_path = g_build_filename (LIBEXECDIR, "ostree", "triggers.d", NULL); - triggerdir = ot_gfile_new_for_path (triggerdir_path); - - enumerator = g_file_enumerate_children (triggerdir, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - NULL, - error); - if (!enumerator) - goto out; - - while ((file_info = g_file_enumerator_next_file (enumerator, NULL, &temp_error)) != NULL) - { - const char *name; - guint32 type; - char *child_path = NULL; - GFile *child = NULL; - gboolean success; - - name = g_file_info_get_attribute_byte_string (file_info, "standard::name"); - type = g_file_info_get_attribute_uint32 (file_info, "standard::type"); - - if (type == G_FILE_TYPE_REGULAR && g_str_has_suffix (name, ".trigger")) - { - child_path = g_build_filename (triggerdir_path, name, NULL); - child = ot_gfile_new_for_path (child_path); - - success = check_trigger (self, child, error); - } - else - success = TRUE; - - g_object_unref (file_info); - g_free (child_path); - g_clear_object (&child); - if (!success) - goto out; - } - if (file_info == NULL && temp_error != NULL) - { - g_propagate_error (error, temp_error); - goto out; - } - - ret = TRUE; - out: - g_free (triggerdir_path); - g_clear_object (&triggerdir); - g_clear_object (&enumerator); - return ret; -} diff --git a/src/libostree/ostree-checkout.h b/src/libostree/ostree-checkout.h deleted file mode 100644 index 042cdc8b..00000000 --- a/src/libostree/ostree-checkout.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- - * - * Copyright (C) 2011 Colin Walters - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Colin Walters - */ - -#ifndef _OSTREE_CHECKOUT -#define _OSTREE_CHECKOUT - -#include - -G_BEGIN_DECLS - -#define OSTREE_TYPE_CHECKOUT ostree_checkout_get_type() -#define OSTREE_CHECKOUT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSTREE_TYPE_CHECKOUT, OstreeCheckout)) -#define OSTREE_CHECKOUT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), OSTREE_TYPE_CHECKOUT, OstreeCheckoutClass)) -#define OSTREE_IS_CHECKOUT(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSTREE_TYPE_CHECKOUT)) -#define OSTREE_IS_CHECKOUT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), OSTREE_TYPE_CHECKOUT)) -#define OSTREE_CHECKOUT_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), OSTREE_TYPE_CHECKOUT, OstreeCheckoutClass)) - -typedef struct { - GObject parent; -} OstreeCheckout; - -typedef struct { - GObjectClass parent_class; -} OstreeCheckoutClass; - -GType ostree_checkout_get_type (void); - -OstreeCheckout* ostree_checkout_new (OstreeRepo *repo, - const char *path); - -gboolean ostree_checkout_run_triggers (OstreeCheckout *checkout, - GError **error); - -G_END_DECLS - -#endif /* _OSTREE_CHECKOUT */ diff --git a/src/libostree/ostree.h b/src/libostree/ostree.h index abd71a32..bf4153ae 100644 --- a/src/libostree/ostree.h +++ b/src/libostree/ostree.h @@ -24,7 +24,6 @@ #include #include -#include #include #include diff --git a/src/ostree/main.c b/src/ostree/main.c index 301a512d..3818029f 100644 --- a/src/ostree/main.c +++ b/src/ostree/main.c @@ -43,7 +43,6 @@ static OstreeBuiltin builtins[] = { { "remote", ostree_builtin_remote, 0 }, { "rev-parse", ostree_builtin_rev_parse, 0 }, { "remote", ostree_builtin_remote, 0 }, - { "run-triggers", ostree_builtin_run_triggers, 0 }, { "show", ostree_builtin_show, 0 }, { NULL } }; diff --git a/src/ostree/ot-builtin-checkout.c b/src/ostree/ot-builtin-checkout.c index 3fd40456..05260231 100644 --- a/src/ostree/ot-builtin-checkout.c +++ b/src/ostree/ot-builtin-checkout.c @@ -40,7 +40,6 @@ ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GError **error GOptionContext *context; gboolean ret = FALSE; OstreeRepo *repo = NULL; - OstreeCheckout *checkout = NULL; const char *commit; const char *destination; GFile *destf = NULL; @@ -79,7 +78,6 @@ ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GError **error if (context) g_option_context_free (context); g_clear_object (&repo); - g_clear_object (&checkout); g_clear_object (&destf); return ret; } diff --git a/src/ostree/ot-builtin-compose.c b/src/ostree/ot-builtin-compose.c index a0c51fb1..30d0aec0 100644 --- a/src/ostree/ot-builtin-compose.c +++ b/src/ostree/ot-builtin-compose.c @@ -93,7 +93,6 @@ ostree_builtin_compose (int argc, char **argv, GFile *repo_path, GError **error) GOptionContext *context; gboolean ret = FALSE; OstreeRepo *repo = NULL; - OstreeCheckout *checkout = NULL; char *parent = NULL; GFile *destf = NULL; GHashTable *seen_branches = NULL; @@ -286,7 +285,6 @@ ostree_builtin_compose (int argc, char **argv, GFile *repo_path, GError **error) if (parent_commit_compose_iter) g_variant_iter_free (parent_commit_compose_iter); g_clear_object (&repo); - g_clear_object (&checkout); g_clear_object (&destf); g_clear_object (&metadata_f); g_clear_object (&mtree); diff --git a/src/ostree/ot-builtin-remote.c b/src/ostree/ot-builtin-remote.c index 41510bc5..6ec33460 100644 --- a/src/ostree/ot-builtin-remote.c +++ b/src/ostree/ot-builtin-remote.c @@ -47,7 +47,6 @@ ostree_builtin_remote (int argc, char **argv, GFile *repo_path, GError **error) GOptionContext *context; gboolean ret = FALSE; OstreeRepo *repo = NULL; - OstreeCheckout *checkout = NULL; const char *op; GKeyFile *config = NULL; @@ -99,6 +98,5 @@ ostree_builtin_remote (int argc, char **argv, GFile *repo_path, GError **error) if (config) g_key_file_free (config); g_clear_object (&repo); - g_clear_object (&checkout); return ret; } diff --git a/src/ostree/ot-builtin-run-triggers.c b/src/ostree/ot-builtin-run-triggers.c deleted file mode 100644 index d5be7a32..00000000 --- a/src/ostree/ot-builtin-run-triggers.c +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- - * - * Copyright (C) 2011 Colin Walters - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Colin Walters - */ - -#include "config.h" - -#include "ot-builtins.h" -#include "ostree.h" - -#include - -static gboolean quiet; - -static GOptionEntry options[] = { - { "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, "Don't display informational messages", NULL }, - { NULL } -}; - -gboolean -ostree_builtin_run_triggers (int argc, char **argv, GFile *repo_path, GError **error) -{ - GOptionContext *context; - gboolean ret = FALSE; - OstreeRepo *repo = NULL; - OstreeCheckout *checkout = NULL; - const char *dir; - - context = g_option_context_new ("DIR - Run trigger scripts for directory"); - g_option_context_add_main_entries (context, options, NULL); - - if (!g_option_context_parse (context, &argc, &argv, error)) - goto out; - - repo = ostree_repo_new (repo_path); - if (!ostree_repo_check (repo, error)) - goto out; - - if (argc < 1) - { - gchar *help = g_option_context_get_help (context, TRUE, NULL); - g_printerr ("%s\n", help); - g_free (help); - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "DIR must be specified"); - goto out; - } - - dir = argv[1]; - - checkout = ostree_checkout_new (repo, dir); - if (!ostree_checkout_run_triggers (checkout, error)) - goto out; - - ret = TRUE; - out: - if (context) - g_option_context_free (context); - g_clear_object (&repo); - g_clear_object (&checkout); - return ret; -} diff --git a/src/ostree/ot-builtins.h b/src/ostree/ot-builtins.h index acf2406c..b49a905f 100644 --- a/src/ostree/ot-builtins.h +++ b/src/ostree/ot-builtins.h @@ -36,7 +36,6 @@ gboolean ostree_builtin_init (int argc, char **argv, GFile *repo_path, GError ** gboolean ostree_builtin_local_clone (int argc, char **argv, GFile *repo_path, GError **error); gboolean ostree_builtin_log (int argc, char **argv, GFile *repo_path, GError **error); gboolean ostree_builtin_ls (int argc, char **argv, GFile *repo_path, GError **error); -gboolean ostree_builtin_run_triggers (int argc, char **argv, GFile *repo_path, GError **error); gboolean ostree_builtin_fsck (int argc, char **argv, GFile *repo_path, GError **error); gboolean ostree_builtin_show (int argc, char **argv, GFile *repo_path, GError **error); gboolean ostree_builtin_rev_parse (int argc, char **argv, GFile *repo_path, GError **error); diff --git a/src/triggers/ostree-run-triggers.c b/src/triggers/ostree-run-triggers.c new file mode 100644 index 00000000..29f036b0 --- /dev/null +++ b/src/triggers/ostree-run-triggers.c @@ -0,0 +1,221 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2011,2012 Colin Walters + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Colin Walters + */ + +#include "config.h" + +#include +#include + +static gboolean quiet; + +static GOptionEntry options[] = { + { "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, "Don't display informational messages", NULL }, + { NULL } +}; + +static gboolean +run_trigger (const char *path, + GError **error) +{ + gboolean ret = FALSE; + char *basename = NULL; + GPtrArray *args = NULL; + int estatus; + + basename = g_path_get_basename (path); + + args = g_ptr_array_new (); + + g_ptr_array_add (args, (char*)path); + g_ptr_array_add (args, NULL); + + g_print ("Running trigger: %s\n", path); + if (!g_spawn_sync (NULL, + (char**)args->pdata, + NULL, + 0, + NULL, NULL, NULL, NULL, + &estatus, + error)) + { + g_prefix_error (error, "Failed to run trigger %s: ", basename); + goto out; + } + + ret = TRUE; + out: + g_free (basename); + if (args) + g_ptr_array_free (args, TRUE); + return ret; +} + +static gboolean +check_trigger (GFile *trigger, + GError **error) +{ + gboolean ret = FALSE; + GInputStream *instream = NULL; + GDataInputStream *datain = NULL; + GError *temp_error = NULL; + char *line; + gsize len; + char *ifexecutable_path = NULL; + char *trigger_path = NULL; + gboolean matched = TRUE; + + trigger_path = g_file_get_path (trigger); + + instream = (GInputStream*)g_file_read (trigger, NULL, error); + if (!instream) + goto out; + datain = g_data_input_stream_new (instream); + + while ((line = g_data_input_stream_read_line (datain, &len, NULL, &temp_error)) != NULL) + { + if (g_str_has_prefix (line, "# IfExecutable: ")) + { + char *executable = g_strdup (line + strlen ("# IfExecutable: ")); + g_strchomp (executable); + g_free (ifexecutable_path); + ifexecutable_path = g_find_program_in_path (executable); + g_free (executable); + if (!ifexecutable_path) + { + matched = FALSE; + break; + } + break; + } + g_free (line); + } + if (line == NULL && temp_error != NULL) + { + g_propagate_error (error, temp_error); + goto out; + } + if (matched) + { + if (!run_trigger (trigger_path, error)) + goto out; + } + + ret = TRUE; + out: + g_free (trigger_path); + g_free (ifexecutable_path); + g_clear_object (&instream); + g_clear_object (&datain); + return ret; +} + + +gboolean +run_triggers (GError **error) +{ + gboolean ret = FALSE; + GError *temp_error = NULL; + char *triggerdir_path = NULL; + GFile *triggerdir = NULL; + GFileInfo *file_info = NULL; + GFileEnumerator *enumerator = NULL; + + triggerdir_path = g_build_filename (LIBEXECDIR, "ostree", "triggers.d", NULL); + triggerdir = g_file_new_for_path (triggerdir_path); + + enumerator = g_file_enumerate_children (triggerdir, "standard::name,standard::type", + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL, + error); + if (!enumerator) + goto out; + + while ((file_info = g_file_enumerator_next_file (enumerator, NULL, &temp_error)) != NULL) + { + const char *name; + guint32 type; + char *child_path = NULL; + GFile *child = NULL; + gboolean success; + + name = g_file_info_get_attribute_byte_string (file_info, "standard::name"); + type = g_file_info_get_attribute_uint32 (file_info, "standard::type"); + + if (type == G_FILE_TYPE_REGULAR && g_str_has_suffix (name, ".trigger")) + { + child_path = g_build_filename (triggerdir_path, name, NULL); + child = g_file_new_for_path (child_path); + + success = check_trigger (child, error); + } + else + success = TRUE; + + g_object_unref (file_info); + g_free (child_path); + g_clear_object (&child); + if (!success) + goto out; + } + if (file_info == NULL && temp_error != NULL) + { + g_propagate_error (error, temp_error); + goto out; + } + + ret = TRUE; + out: + g_free (triggerdir_path); + g_clear_object (&triggerdir); + g_clear_object (&enumerator); + return ret; +} + +int +main (int argc, + char **argv) +{ + GOptionContext *context; + GError *real_error = NULL; + GError **error = &real_error; + gboolean ret = FALSE; + + g_type_init (); + + context = g_option_context_new ("- Regenerate caches in operating system tree"); + g_option_context_add_main_entries (context, options, NULL); + + if (!g_option_context_parse (context, &argc, &argv, error)) + goto out; + + if (!run_triggers (error)) + goto out; + + ret = TRUE; + out: + if (real_error) + g_printerr ("%s\n", real_error->message); + g_clear_error (&real_error); + if (!ret) + return 1; + return 0; +} diff --git a/triggers.d/desktop-database.trigger b/src/triggers/triggers.d/desktop-database.trigger similarity index 100% rename from triggers.d/desktop-database.trigger rename to src/triggers/triggers.d/desktop-database.trigger diff --git a/triggers.d/gdk-pixbuf.trigger b/src/triggers/triggers.d/gdk-pixbuf.trigger similarity index 100% rename from triggers.d/gdk-pixbuf.trigger rename to src/triggers/triggers.d/gdk-pixbuf.trigger diff --git a/triggers.d/glib.trigger b/src/triggers/triggers.d/glib.trigger similarity index 100% rename from triggers.d/glib.trigger rename to src/triggers/triggers.d/glib.trigger diff --git a/triggers.d/gtk+.trigger b/src/triggers/triggers.d/gtk+.trigger similarity index 100% rename from triggers.d/gtk+.trigger rename to src/triggers/triggers.d/gtk+.trigger diff --git a/triggers.d/immodules.trigger b/src/triggers/triggers.d/immodules.trigger similarity index 100% rename from triggers.d/immodules.trigger rename to src/triggers/triggers.d/immodules.trigger diff --git a/triggers.d/ldconfig.trigger b/src/triggers/triggers.d/ldconfig.trigger similarity index 100% rename from triggers.d/ldconfig.trigger rename to src/triggers/triggers.d/ldconfig.trigger diff --git a/triggers.d/mime-database.trigger b/src/triggers/triggers.d/mime-database.trigger similarity index 100% rename from triggers.d/mime-database.trigger rename to src/triggers/triggers.d/mime-database.trigger diff --git a/triggers.d/pango.trigger b/src/triggers/triggers.d/pango.trigger similarity index 95% rename from triggers.d/pango.trigger rename to src/triggers/triggers.d/pango.trigger index ebd60f41..e5e19cee 100755 --- a/triggers.d/pango.trigger +++ b/src/triggers/triggers.d/pango.trigger @@ -22,6 +22,5 @@ # IfExecutable: pango-querymodules # REMatch: /lib.*/pango/.*/modules/.*\.so -OSTREE_ROOT=`pwd` -DEST=./usr/etc/pango/pango.modules +DEST=/etc/pango/pango.modules pango-querymodules > ${DEST}.tmp && mv ${DEST}.tmp ${DEST}