forked from Mirrors/flatpak-builder
common: Add and use xdg_app_dir_deploy_update()
parent
423a5af15b
commit
be4f0d86d8
|
@ -49,10 +49,9 @@ xdg_app_builtin_update_runtime (int argc, char **argv, GCancellable *cancellable
|
|||
g_autoptr(XdgAppDir) dir = NULL;
|
||||
const char *runtime;
|
||||
const char *branch = NULL;
|
||||
g_autofree char *previous_deployment = NULL;
|
||||
g_autofree char *ref = NULL;
|
||||
g_autofree char *repository = NULL;
|
||||
GError *my_error;
|
||||
gboolean was_updated;
|
||||
|
||||
context = g_option_context_new ("RUNTIME [BRANCH] - Update a runtime");
|
||||
|
||||
|
@ -78,31 +77,13 @@ xdg_app_builtin_update_runtime (int argc, char **argv, GCancellable *cancellable
|
|||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
previous_deployment = xdg_app_dir_read_active (dir, ref, cancellable);
|
||||
if (!xdg_app_dir_deploy_update (dir, ref, opt_commit, &was_updated, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
my_error = NULL;
|
||||
if (!xdg_app_dir_deploy (dir, ref, opt_commit, cancellable, &my_error))
|
||||
if (was_updated)
|
||||
{
|
||||
if (g_error_matches (my_error, XDG_APP_DIR_ERROR, XDG_APP_DIR_ERROR_ALREADY_DEPLOYED))
|
||||
g_error_free (my_error);
|
||||
else
|
||||
{
|
||||
g_propagate_error (error, my_error);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (previous_deployment != NULL)
|
||||
{
|
||||
if (!xdg_app_dir_undeploy (dir, ref, previous_deployment,
|
||||
opt_force_remove,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
if (!xdg_app_dir_prune (dir, cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
if (!xdg_app_dir_prune (dir, cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
xdg_app_dir_cleanup_removed (dir, cancellable, NULL);
|
||||
|
@ -119,8 +100,7 @@ xdg_app_builtin_update_app (int argc, char **argv, GCancellable *cancellable, GE
|
|||
const char *branch = NULL;
|
||||
g_autofree char *ref = NULL;
|
||||
g_autofree char *repository = NULL;
|
||||
g_autofree char *previous_deployment = NULL;
|
||||
GError *my_error;
|
||||
gboolean was_updated;
|
||||
|
||||
context = g_option_context_new ("APP [BRANCH] - Update an application");
|
||||
|
||||
|
@ -146,36 +126,21 @@ xdg_app_builtin_update_app (int argc, char **argv, GCancellable *cancellable, GE
|
|||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
previous_deployment = xdg_app_dir_read_active (dir, ref, cancellable);
|
||||
if (!xdg_app_dir_deploy_update (dir, ref, opt_commit, &was_updated, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
my_error = NULL;
|
||||
if (!xdg_app_dir_deploy (dir, ref, opt_commit, cancellable, &my_error))
|
||||
if (was_updated)
|
||||
{
|
||||
if (g_error_matches (my_error, XDG_APP_DIR_ERROR, XDG_APP_DIR_ERROR_ALREADY_DEPLOYED))
|
||||
g_error_free (my_error);
|
||||
else
|
||||
{
|
||||
g_propagate_error (error, my_error);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (previous_deployment != NULL)
|
||||
{
|
||||
if (!xdg_app_dir_undeploy (dir, ref, previous_deployment,
|
||||
opt_force_remove,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
if (!xdg_app_dir_prune (dir, cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!xdg_app_dir_update_exports (dir, app, cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (was_updated)
|
||||
{
|
||||
if (!xdg_app_dir_prune (dir, cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
xdg_app_dir_cleanup_removed (dir, cancellable, NULL);
|
||||
|
||||
return TRUE;
|
||||
|
|
|
@ -1641,6 +1641,49 @@ xdg_app_dir_deploy (XdgAppDir *self,
|
|||
return ret;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
previous_deployment = xdg_app_dir_read_active (self, ref, cancellable);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
g_propagate_error (error, my_error);
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (was_updated)
|
||||
*was_updated = TRUE;
|
||||
|
||||
if (previous_deployment != NULL)
|
||||
{
|
||||
if (!xdg_app_dir_undeploy (self, ref, previous_deployment,
|
||||
FALSE,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
xdg_app_dir_collect_deployed_refs (XdgAppDir *self,
|
||||
const char *type,
|
||||
|
|
|
@ -155,6 +155,12 @@ gboolean xdg_app_dir_deploy (XdgAppDir *self,
|
|||
const char *checksum,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
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,
|
||||
const char *ref,
|
||||
const char *checksum,
|
||||
|
|
|
@ -573,9 +573,8 @@ xdg_app_installation_update (XdgAppInstallation *self,
|
|||
g_autoptr(GMainContext) main_context = NULL;
|
||||
g_autoptr(OstreeAsyncProgress) ostree_progress = NULL;
|
||||
g_autofree char *remote_name = NULL;
|
||||
g_autofree char *previous_deployment = NULL;
|
||||
XdgAppInstalledRef *result = NULL;
|
||||
g_autoptr(GError) my_error = NULL;
|
||||
gboolean was_updated;
|
||||
|
||||
ref = xdg_app_compose_ref (kind == XDG_APP_REF_KIND_APP, name, version, arch, error);
|
||||
if (ref == NULL)
|
||||
|
@ -603,40 +602,25 @@ xdg_app_installation_update (XdgAppInstallation *self,
|
|||
ostree_progress, cancellable, error))
|
||||
goto out;
|
||||
|
||||
previous_deployment = xdg_app_dir_read_active (dir_clone, ref, cancellable);
|
||||
if (!xdg_app_dir_deploy_update (dir_clone, ref, NULL, &was_updated, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
if (!xdg_app_dir_deploy (dir_clone, ref, NULL, cancellable, &my_error))
|
||||
if (was_updated && kind == XDG_APP_REF_KIND_APP)
|
||||
{
|
||||
if (!g_error_matches (my_error, XDG_APP_DIR_ERROR, XDG_APP_DIR_ERROR_ALREADY_DEPLOYED))
|
||||
{
|
||||
g_propagate_error (error, my_error);
|
||||
goto out;
|
||||
}
|
||||
if (!xdg_app_dir_update_exports (dir_clone, name, cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
else
|
||||
|
||||
result = get_ref (self, ref, cancellable);
|
||||
|
||||
if (was_updated)
|
||||
{
|
||||
if (previous_deployment != NULL)
|
||||
{
|
||||
if (!xdg_app_dir_undeploy (dir_clone, ref, previous_deployment,
|
||||
FALSE,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (!xdg_app_dir_prune (dir_clone, cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (kind == XDG_APP_REF_KIND_APP)
|
||||
{
|
||||
if (!xdg_app_dir_update_exports (dir_clone, name, cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
if (!xdg_app_dir_prune (dir_clone, cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
xdg_app_dir_cleanup_removed (dir_clone, cancellable, NULL);
|
||||
|
||||
result = get_ref (self, ref, cancellable);
|
||||
|
||||
out:
|
||||
if (main_context)
|
||||
g_main_context_pop_thread_default (main_context);
|
||||
|
@ -675,7 +659,7 @@ xdg_app_installation_uninstall (XdgAppInstallation *self,
|
|||
|
||||
ref = xdg_app_compose_ref (kind == XDG_APP_REF_KIND_APP, name, version, arch, error);
|
||||
if (ref == NULL)
|
||||
return NULL;
|
||||
return FALSE;
|
||||
|
||||
remote_name = xdg_app_dir_get_origin (priv->dir, ref, cancellable, error);
|
||||
if (remote_name == NULL)
|
||||
|
|
Loading…
Reference in New Issue