From 3cc45ccf137d0b0eeba81af041d816b0cbfb6fc7 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 7 Apr 2016 20:35:32 +0200 Subject: Add support for subpath limited installs This allows you to install e.g. org.freedesktop.Platform.Locale but only the /sv subdir, and replaces using separate branches for each locale. --- lib/xdg-app-installation.c | 14 +++++++++++--- lib/xdg-app-installed-ref-private.h | 1 + lib/xdg-app-installed-ref.c | 27 ++++++++++++++++++++++++++- lib/xdg-app-installed-ref.h | 13 +++++++------ 4 files changed, 45 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/xdg-app-installation.c b/lib/xdg-app-installation.c index 3ca83b5..0219be4 100644 --- a/lib/xdg-app-installation.c +++ b/lib/xdg-app-installation.c @@ -290,6 +290,7 @@ get_ref (XdgAppInstallation *self, g_autoptr(GFile) deploy_subdir = NULL; g_autofree char *deploy_path = NULL; g_autofree char *latest_commit = NULL; + g_auto(GStrv) subpaths = NULL; gboolean is_current = FALSE; guint64 installed_size = 0; @@ -297,6 +298,8 @@ get_ref (XdgAppInstallation *self, origin = xdg_app_dir_get_origin (priv->dir, full_ref, NULL, NULL); commit = xdg_app_dir_read_active (priv->dir, full_ref, cancellable); + subpaths = xdg_app_dir_get_subpaths (priv->dir, full_ref, cancellable, NULL); + deploy_dir = xdg_app_dir_get_deploy_dir (priv->dir, full_ref); if (deploy_dir && commit) { @@ -323,7 +326,7 @@ get_ref (XdgAppInstallation *self, return xdg_app_installed_ref_new (full_ref, commit, latest_commit, - origin, + origin, subpaths, deploy_path, installed_size, is_current); @@ -992,7 +995,7 @@ xdg_app_installation_install (XdgAppInstallation *self, g_object_set_data (G_OBJECT (ostree_progress), "last_progress", GUINT_TO_POINTER(0)); } - if (!xdg_app_dir_pull (dir_clone, remote_name, ref, + if (!xdg_app_dir_pull (dir_clone, remote_name, ref, NULL, ostree_progress, cancellable, error)) goto out; @@ -1088,6 +1091,7 @@ xdg_app_installation_update (XdgAppInstallation *self, XdgAppInstalledRef *result = NULL; gboolean was_updated = FALSE; g_auto(GLnxLockFile) lock = GLNX_LOCK_FILE_INIT; + g_auto(GStrv) subpaths = NULL; ref = xdg_app_compose_ref (kind == XDG_APP_REF_KIND_APP, name, branch, arch, error); if (ref == NULL) @@ -1106,6 +1110,10 @@ xdg_app_installation_update (XdgAppInstallation *self, if (remote_name == NULL) return NULL; + subpaths = xdg_app_dir_get_subpaths (priv->dir, ref, cancellable, error); + if (subpaths == NULL) + return FALSE; + /* Pull, prune, etc are not threadsafe, so we work on a copy */ dir_clone = xdg_app_dir_clone (priv->dir); @@ -1122,7 +1130,7 @@ xdg_app_installation_update (XdgAppInstallation *self, if ((flags & XDG_APP_UPDATE_FLAGS_NO_PULL) == 0) { - if (!xdg_app_dir_pull (dir_clone, remote_name, ref, + if (!xdg_app_dir_pull (dir_clone, remote_name, ref, subpaths, ostree_progress, cancellable, error)) goto out; } diff --git a/lib/xdg-app-installed-ref-private.h b/lib/xdg-app-installed-ref-private.h index c192aa6..3b7bb59 100644 --- a/lib/xdg-app-installed-ref-private.h +++ b/lib/xdg-app-installed-ref-private.h @@ -32,6 +32,7 @@ XdgAppInstalledRef *xdg_app_installed_ref_new (const char *full_ref, const char *commit, const char *latest_commit, const char *origin, + char **subpaths, const char *deploy_dir, guint64 installed_size, gboolean current); diff --git a/lib/xdg-app-installed-ref.c b/lib/xdg-app-installed-ref.c index da29742..853dc7b 100644 --- a/lib/xdg-app-installed-ref.c +++ b/lib/xdg-app-installed-ref.c @@ -44,6 +44,7 @@ struct _XdgAppInstalledRefPrivate char *origin; char *latest_commit; char *deploy_dir; + char **subpaths; guint64 installed_size; }; @@ -56,7 +57,8 @@ enum { PROP_ORIGIN, PROP_LATEST_COMMIT, PROP_DEPLOY_DIR, - PROP_INSTALLED_SIZE + PROP_INSTALLED_SIZE, + PROP_SUBPATHS }; static void @@ -67,6 +69,7 @@ xdg_app_installed_ref_finalize (GObject *object) g_free (priv->origin); g_free (priv->deploy_dir); + g_strfreev (priv->subpaths); G_OBJECT_CLASS (xdg_app_installed_ref_parent_class)->finalize (object); } @@ -105,6 +108,11 @@ xdg_app_installed_ref_set_property (GObject *object, priv->deploy_dir = g_value_dup_string (value); break; + case PROP_SUBPATHS: + g_clear_pointer (&priv->subpaths, g_strfreev); + priv->subpaths = g_strdupv (g_value_get_boxed (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -142,6 +150,10 @@ xdg_app_installed_ref_get_property (GObject *object, g_value_set_string (value, priv->deploy_dir); break; + case PROP_SUBPATHS: + g_value_set_boxed (value, priv->subpaths); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -192,6 +204,13 @@ xdg_app_installed_ref_class_init (XdgAppInstalledRefClass *klass) "Where the application is installed", NULL, G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_SUBPATHS, + g_param_spec_boxed ("subpaths", + "", + "", + G_TYPE_STRV, + G_PARAM_READWRITE)); } static void @@ -319,6 +338,7 @@ xdg_app_installed_ref_new (const char *full_ref, const char *commit, const char *latest_commit, const char *origin, + char **subpaths, const char *deploy_dir, guint64 installed_size, gboolean is_current) @@ -332,6 +352,10 @@ xdg_app_installed_ref_new (const char *full_ref, if (strcmp (parts[0], "app") != 0) kind = XDG_APP_REF_KIND_RUNTIME; + /* Canonicalize the "no subpaths" case */ + if (subpaths && *subpaths == NULL) + subpaths = NULL; + ref = g_object_new (XDG_APP_TYPE_INSTALLED_REF, "kind", kind, "name", parts[1], @@ -340,6 +364,7 @@ xdg_app_installed_ref_new (const char *full_ref, "commit", commit, "latest-commit", latest_commit, "origin", origin, + "subpaths", subpaths, "is-current", is_current, "installed-size", installed_size, "deploy-dir", deploy_dir, diff --git a/lib/xdg-app-installed-ref.h b/lib/xdg-app-installed-ref.h index 624bf8a..3fdf069 100644 --- a/lib/xdg-app-installed-ref.h +++ b/lib/xdg-app-installed-ref.h @@ -48,12 +48,13 @@ typedef struct { G_DEFINE_AUTOPTR_CLEANUP_FUNC(XdgAppInstalledRef, g_object_unref) #endif -XDG_APP_EXTERN const char *xdg_app_installed_ref_get_origin (XdgAppInstalledRef *self); -XDG_APP_EXTERN guint64 xdg_app_installed_ref_get_installed_size (XdgAppInstalledRef *self); -XDG_APP_EXTERN const char *xdg_app_installed_ref_get_deploy_dir (XdgAppInstalledRef *self); -XDG_APP_EXTERN const char *xdg_app_installed_ref_get_latest_commit (XdgAppInstalledRef *self); -XDG_APP_EXTERN gboolean xdg_app_installed_ref_get_is_current (XdgAppInstalledRef *self); -XDG_APP_EXTERN GBytes *xdg_app_installed_ref_load_metadata (XdgAppInstalledRef *self, +XDG_APP_EXTERN const char *xdg_app_installed_ref_get_origin (XdgAppInstalledRef *self); +XDG_APP_EXTERN const char **xdg_app_installed_ref_get_subpaths (XdgAppInstalledRef *self); +XDG_APP_EXTERN guint64 xdg_app_installed_ref_get_installed_size (XdgAppInstalledRef *self); +XDG_APP_EXTERN const char *xdg_app_installed_ref_get_deploy_dir (XdgAppInstalledRef *self); +XDG_APP_EXTERN const char *xdg_app_installed_ref_get_latest_commit (XdgAppInstalledRef *self); +XDG_APP_EXTERN gboolean xdg_app_installed_ref_get_is_current (XdgAppInstalledRef *self); +XDG_APP_EXTERN GBytes *xdg_app_installed_ref_load_metadata (XdgAppInstalledRef *self, GCancellable *cancellable, GError **error); -- cgit v1.2.1