summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-04-21 20:19:01 +0200
committerAlexander Larsson <alexl@redhat.com>2016-04-21 20:19:01 +0200
commit91eda8919e06d6d7752a522e4161fb7d2611cbed (patch)
treeffdb0e79d451584a71e46c106540488303799e12
parent21dd53d1ff7541c4dc3e95da3ae15f5eb2a62778 (diff)
downloadxdg-app-91eda8919e06d6d7752a522e4161fb7d2611cbed.tar.gz
common: Move duplicated code into xdg_app_dir_deploy_update
-rw-r--r--app/xdg-app-builtins-update.c25
-rw-r--r--common/xdg-app-dir.c52
-rw-r--r--common/xdg-app-dir.h1
-rw-r--r--lib/xdg-app-installation.c28
4 files changed, 37 insertions, 69 deletions
diff --git a/app/xdg-app-builtins-update.c b/app/xdg-app-builtins-update.c
index 15a1475..a5aa0d8 100644
--- a/app/xdg-app-builtins-update.c
+++ b/app/xdg-app-builtins-update.c
@@ -78,9 +78,7 @@ do_update (XdgAppDir* dir,
g_autofree char *ref = NULL;
g_autofree char *repository = NULL;
g_auto(GStrv) subpaths = NULL;
- gboolean was_updated = FALSE;
gboolean is_app;
- g_auto(GLnxLockFile) lock = GLNX_LOCK_FILE_INIT;
ref = xdg_app_dir_find_installed_ref (dir,
name,
@@ -108,28 +106,7 @@ do_update (XdgAppDir* dir,
if (!opt_no_deploy)
{
- if (!xdg_app_dir_lock (dir, &lock,
- cancellable, error))
- return FALSE;
-
- if (!xdg_app_dir_deploy_update (dir, ref, opt_commit, &was_updated, cancellable, error))
- return FALSE;
-
- if (was_updated && is_app)
- {
- if (!xdg_app_dir_update_exports (dir, name, cancellable, error))
- return FALSE;
- }
-
- glnx_release_lock_file (&lock);
- }
-
- if (was_updated)
- {
- if (!xdg_app_dir_prune (dir, cancellable, error))
- return FALSE;
-
- if (!xdg_app_dir_mark_changed (dir, error))
+ if (!xdg_app_dir_deploy_update (dir, ref, opt_commit, cancellable, error))
return FALSE;
}
diff --git a/common/xdg-app-dir.c b/common/xdg-app-dir.c
index 79bff57..3bdfd2b 100644
--- a/common/xdg-app-dir.c
+++ b/common/xdg-app-dir.c
@@ -2184,41 +2184,57 @@ gboolean
xdg_app_dir_deploy_update (XdgAppDir *self,
const char *ref,
const char *checksum_or_latest,
- gboolean *was_updated,
GCancellable *cancellable,
GError **error)
{
g_autofree char *previous_deployment = NULL;
g_autoptr(GError) my_error = NULL;
+ g_auto(GLnxLockFile) lock = GLNX_LOCK_FILE_INIT;
+
+ if (!xdg_app_dir_lock (self, &lock,
+ cancellable, error))
+ return FALSE;
previous_deployment = xdg_app_dir_read_active (self, ref, cancellable);
- if (!xdg_app_dir_deploy (self, ref, checksum_or_latest, cancellable, &my_error))
+ if (!xdg_app_dir_deploy (self, ref, checksum_or_latest,
+ cancellable, &my_error))
{
- if (g_error_matches (my_error, XDG_APP_DIR_ERROR, XDG_APP_DIR_ERROR_ALREADY_DEPLOYED))
- {
- if (was_updated)
- *was_updated = FALSE;
- return TRUE;
- }
+ if (g_error_matches (my_error, XDG_APP_DIR_ERROR,
+ XDG_APP_DIR_ERROR_ALREADY_DEPLOYED))
+ return TRUE;
g_propagate_error (error, my_error);
return FALSE;
}
- else
+
+ if (previous_deployment != NULL)
{
- if (was_updated)
- *was_updated = TRUE;
+ if (!xdg_app_dir_undeploy (self, ref, previous_deployment,
+ FALSE,
+ cancellable, error))
+ return FALSE;
+ }
- if (previous_deployment != NULL)
- {
- if (!xdg_app_dir_undeploy (self, ref, previous_deployment,
- FALSE,
- cancellable, error))
- return FALSE;
- }
+ if (g_str_has_prefix (ref, "app/"))
+ {
+ g_auto(GStrv) ref_parts = g_strsplit (ref, "/", -1);
+
+ if (!xdg_app_dir_update_exports (self, ref_parts[1], cancellable, error))
+ return FALSE;
}
+ /* Release lock before doing prune */
+ glnx_release_lock_file (&lock);
+
+ if (!xdg_app_dir_prune (self, cancellable, error))
+ return FALSE;
+
+ if (!xdg_app_dir_mark_changed (self, error))
+ return FALSE;
+
+ xdg_app_dir_cleanup_removed (self, cancellable, NULL);
+
return TRUE;
}
diff --git a/common/xdg-app-dir.h b/common/xdg-app-dir.h
index 7665fc7..d94531f 100644
--- a/common/xdg-app-dir.h
+++ b/common/xdg-app-dir.h
@@ -209,7 +209,6 @@ gboolean xdg_app_dir_deploy (XdgAppDir *self,
gboolean xdg_app_dir_deploy_update (XdgAppDir *self,
const char *ref,
const char *checksum,
- gboolean *was_updated,
GCancellable *cancellable,
GError **error);
gboolean xdg_app_dir_undeploy (XdgAppDir *self,
diff --git a/lib/xdg-app-installation.c b/lib/xdg-app-installation.c
index c6ab372..26b0f87 100644
--- a/lib/xdg-app-installation.c
+++ b/lib/xdg-app-installation.c
@@ -1092,8 +1092,6 @@ xdg_app_installation_update (XdgAppInstallation *self,
g_autoptr(OstreeAsyncProgress) ostree_progress = NULL;
g_autofree char *remote_name = NULL;
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);
@@ -1140,35 +1138,13 @@ xdg_app_installation_update (XdgAppInstallation *self,
if ((flags & XDG_APP_UPDATE_FLAGS_NO_DEPLOY) == 0)
{
- if (!xdg_app_dir_lock (dir_clone, &lock,
- cancellable, error))
+ if (!xdg_app_dir_deploy_update (dir_clone, ref, NULL,
+ cancellable, error))
goto out;
-
- if (!xdg_app_dir_deploy_update (dir_clone, ref, NULL, &was_updated, cancellable, error))
- return FALSE;
-
- if (was_updated && kind == XDG_APP_REF_KIND_APP)
- {
- if (!xdg_app_dir_update_exports (dir_clone, name, cancellable, error))
- goto out;
- }
}
result = get_ref (self, ref, cancellable);
- glnx_release_lock_file (&lock);
-
- if (was_updated)
- {
- if (!xdg_app_dir_prune (dir_clone, cancellable, error))
- goto out;
-
- if (!xdg_app_dir_mark_changed (dir_clone, error))
- goto out;
- }
-
- xdg_app_dir_cleanup_removed (dir_clone, cancellable, NULL);
-
out:
if (main_context)
g_main_context_pop_thread_default (main_context);