Add triggers for exports

This runs the triggers in a read-only environment to update things
like desktop file databases, icon caches and mimeinfo databases.
tingping/wmclass
Alexander Larsson 2015-01-15 21:44:22 +01:00
parent 2fd90ae415
commit daf41bab9c
5 changed files with 120 additions and 4 deletions

View File

@ -5,10 +5,18 @@ SUBDIRS = doc
endif
AM_CPPFLAGS = \
-DXDG_APP_BASEDIR=\"$(datadir)/xdg-app\" \
-DXDG_APP_BASEDIR=\"$(pkgdatadir)\" \
-DXDG_APP_TRIGGERDIR=\"$(pkgdatadir)/triggers\" \
-DHELPER=\"$(bindir)/xdg-app-helper\" \
$(NULL)
triggersdir = $(pkgdatadir)/triggers
dist_triggers_SCRIPTS = \
triggers/gtk-icon-cache.trigger \
triggers/mime-database.trigger \
triggers/desktop-database.trigger \
$(NULL)
bin_PROGRAMS = \
xdg-app-helper \
xdg-app \

View File

@ -0,0 +1,5 @@
#!/bin/sh
if test \( -x "$(which update-desktop-database 2>/dev/null)" \) -a \( -d /self/exports/share/applications \); then
exec update-desktop-database -q /self/exports/share/applications
fi

View File

@ -0,0 +1,13 @@
#!/bin/sh
if test \( -x "$(which gtk-update-icon-cache 2>/dev/null)" \) -a \( -d /self/exports/share/icons/hicolor \); then
cp /usr/share/icons/hicolor/index.theme /self/exports/share/icons/hicolor/
for dir in /self/exports/share/icons/*; do
if test -f $dir/index.theme; then
if ! gtk-update-icon-cache --quiet $dir; then
echo "Failed to run gtk-update-icon-cache for $dir"
exit 1
fi
fi
done
fi

View File

@ -0,0 +1,5 @@
#!/bin/sh
if test \( -x "$(which update-mime-database 2>/dev/null)" \) -a \( -d /self/exports/share/mime/packages \); then
exec update-mime-database /self/exports/share/mime
fi

View File

@ -325,6 +325,85 @@ xdg_app_dir_set_active (XdgAppDir *self,
}
gboolean
xdg_app_dir_run_triggers (XdgAppDir *self,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
gs_unref_object GFileEnumerator *dir_enum = NULL;
gs_unref_object GFileInfo *child_info = NULL;
gs_unref_object GFile *triggersdir = NULL;
gs_unref_object GFile *exports = NULL;
GError *temp_error = NULL;
g_debug ("running triggers");
exports = xdg_app_dir_get_exports_dir (self);
triggersdir = g_file_new_for_path (XDG_APP_TRIGGERDIR);
dir_enum = g_file_enumerate_children (triggersdir, "standard::type,standard::name",
0, cancellable, error);
if (!dir_enum)
goto out;
while ((child_info = g_file_enumerator_next_file (dir_enum, cancellable, &temp_error)) != NULL)
{
gs_unref_object GFile *child = NULL;
const char *name;
GError *trigger_error = NULL;
name = g_file_info_get_name (child_info);
child = g_file_get_child (triggersdir, name);
if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_REGULAR &&
g_str_has_suffix (name, ".trigger"))
{
gs_unref_ptrarray GPtrArray *argv_array = NULL;
g_debug ("running trigger %s", name);
argv_array = g_ptr_array_new_with_free_func (g_free);
g_ptr_array_add (argv_array, g_strdup (HELPER));
g_ptr_array_add (argv_array, g_strdup ("-a"));
g_ptr_array_add (argv_array, g_file_get_path (self->basedir));
g_ptr_array_add (argv_array, g_strdup ("-e"));
g_ptr_array_add (argv_array, g_strdup ("-F"));
g_ptr_array_add (argv_array, g_strdup ("/usr"));
g_ptr_array_add (argv_array, g_file_get_path (child));
g_ptr_array_add (argv_array, NULL);
if (!g_spawn_sync ("/",
(char **)argv_array->pdata,
NULL,
G_SPAWN_DEFAULT,
NULL, NULL,
NULL, NULL,
NULL, &trigger_error))
{
g_warning ("Error running trigger %s: %s", name, trigger_error->message);
g_clear_error (&trigger_error);
}
}
g_clear_object (&child_info);
}
if (temp_error != NULL)
{
g_propagate_error (error, temp_error);
goto out;
}
ret = TRUE;
out:
return ret;
}
gboolean
xdg_app_dir_deploy (XdgAppDir *self,
const char *ref,
@ -333,6 +412,7 @@ xdg_app_dir_deploy (XdgAppDir *self,
GError **error)
{
gboolean ret = FALSE;
gboolean is_app;
gs_free char *resolved_ref = NULL;
gs_unref_object GFile *root = NULL;
gs_unref_object GFileInfo *file_info = NULL;
@ -386,8 +466,10 @@ xdg_app_dir_deploy (XdgAppDir *self,
G_FILE_CREATE_NONE, NULL, cancellable, error))
goto out;
is_app = g_str_has_prefix (ref, "app");
exports = xdg_app_dir_get_exports_dir (self);
if (g_str_has_prefix (ref, "app"))
if (is_app)
{
export = g_file_get_child (checkoutdir, "export");
if (g_file_query_exists (export, cancellable))
@ -409,10 +491,13 @@ xdg_app_dir_deploy (XdgAppDir *self,
if (!xdg_app_dir_set_active (self, ref, checksum, cancellable, error))
goto out;
if (g_file_query_exists (exports, cancellable))
if (is_app && g_file_query_exists (exports, cancellable))
{
if (!xdg_app_remove_dangling_symlinks (exports, cancellable, error))
goto out;
goto out;
if (!xdg_app_dir_run_triggers (self, cancellable, error))
goto out;
}
ret = TRUE;