[ostree] core: Move triggers into separate binary: ostree-run-triggers
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] core: Move triggers into separate binary: ostree-run-triggers
- Date: Fri, 13 Jan 2012 21:47:30 +0000 (UTC)
commit 40226c2769a295c2d5be8d35dc19477f634624e8
Author: Colin Walters <walters verbum org>
Date: Fri Jan 13 15:08:27 2012 -0500
core: Move triggers into separate binary: ostree-run-triggers
I'm trying to keep ostree as being closer to just being the versioning
filesystem, so let's split out the triggers into a different binary
(although still namespaced ostree-).
Makefile-libostree.am | 2 -
Makefile-ostree.am | 1 -
Makefile-triggers.am | 22 +-
src/libostree/ostree-checkout.c | 361 --------------------
src/libostree/ostree-checkout.h | 60 ----
src/libostree/ostree.h | 1 -
src/ostree/main.c | 1 -
src/ostree/ot-builtin-checkout.c | 2 -
src/ostree/ot-builtin-compose.c | 2 -
src/ostree/ot-builtin-remote.c | 2 -
src/ostree/ot-builtin-run-triggers.c | 79 -----
src/ostree/ot-builtins.h | 1 -
src/triggers/ostree-run-triggers.c | 221 ++++++++++++
.../triggers/triggers.d}/desktop-database.trigger | 0
.../triggers/triggers.d}/gdk-pixbuf.trigger | 0
.../triggers/triggers.d}/glib.trigger | 0
.../triggers/triggers.d}/gtk+.trigger | 0
.../triggers/triggers.d}/immodules.trigger | 0
.../triggers/triggers.d}/ldconfig.trigger | 0
.../triggers/triggers.d}/mime-database.trigger | 0
.../triggers/triggers.d}/pango.trigger | 3 +-
21 files changed, 236 insertions(+), 522 deletions(-)
---
diff --git a/Makefile-libostree.am b/Makefile-libostree.am
index adcddf7..20af32c 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 8c8f8a2..4d10bc2 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 96beff0..83af6ce 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.h b/src/libostree/ostree.h
index abd71a3..bf4153a 100644
--- a/src/libostree/ostree.h
+++ b/src/libostree/ostree.h
@@ -24,7 +24,6 @@
#include <ostree-core.h>
#include <ostree-repo.h>
-#include <ostree-checkout.h>
#include <ostree-mutable-tree.h>
#include <ostree-repo-file.h>
diff --git a/src/ostree/main.c b/src/ostree/main.c
index 301a512..3818029 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 3fd4045..0526023 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 a0c51fb..30d0aec 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 41510bc..6ec3346 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-builtins.h b/src/ostree/ot-builtins.h
index acf2406..b49a905 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 0000000..29f036b
--- /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 <walters verbum org>
+ *
+ * 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 <walters verbum org>
+ */
+
+#include "config.h"
+
+#include <gio/gio.h>
+#include <string.h>
+
+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 ebd60f4..e5e19ce 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}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]