Add xdg_app_dir_deploy_install helper

This commit is contained in:
Alexander Larsson committed 2016-04-21 20:59:26 +02:00
1 parent 91eda8919e
commit d314df07c1
4 files changed
+89 -160

No files matched your search

+5 -79
View File
@@ -110,14 +110,12 @@ install_bundle (XdgAppDir *dir,
const char *filename;
g_autofree char *ref = NULL;
g_autofree char *origin = NULL;
gboolean created_deploy_base = FALSE;
gboolean added_remote = FALSE;
g_autofree char *to_checksum = NULL;
g_auto(GStrv) parts = NULL;
g_autoptr(GBytes) gpg_data = NULL;
g_autofree char *remote = NULL;
OstreeRepo *repo;
g_auto(GLnxLockFile) lock = GLNX_LOCK_FILE_INIT;
g_autoptr(GVariant) metadata = NULL;
g_autofree char *basename = NULL;
@@ -183,43 +181,12 @@ install_bundle (XdgAppDir *dir,
error))
goto out;
if (!xdg_app_dir_lock (dir, &lock,
cancellable, error))
return FALSE;
if (!g_file_make_directory_with_parents (deploy_base, cancellable, error))
goto out;
created_deploy_base = TRUE;
if (!xdg_app_dir_set_origin (dir, ref, remote, cancellable, error))
goto out;
if (!xdg_app_dir_deploy (dir, ref, to_checksum, cancellable, error))
goto out;
if (strcmp (parts[0], "app") == 0)
{
if (!xdg_app_dir_make_current_ref (dir, ref, cancellable, error))
goto out;
if (!xdg_app_dir_update_exports (dir, parts[1], cancellable, error))
goto out;
}
glnx_release_lock_file (&lock);
xdg_app_dir_cleanup_removed (dir, cancellable, NULL);
if (!xdg_app_dir_mark_changed (dir, error))
if (!xdg_app_dir_deploy_install (dir, ref, remote, NULL, cancellable, error))
goto out;
ret = TRUE;
out:
if (created_deploy_base && !ret)
gs_shutil_rm_rf (deploy_base, cancellable, NULL);
if (added_remote && !ret)
ostree_repo_remote_delete (repo, remote, NULL, NULL);
@@ -229,7 +196,6 @@ install_bundle (XdgAppDir *dir,
gboolean
xdg_app_builtin_install (int argc, char **argv, GCancellable *cancellable, GError **error)
{
gboolean ret = FALSE;
g_autoptr(GOptionContext) context = NULL;
g_autoptr(XdgAppDir) dir = NULL;
g_autoptr(GFile) deploy_base = NULL;
@@ -239,8 +205,6 @@ xdg_app_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro
g_autofree char *ref = NULL;
g_autofree char *installed_ref = NULL;
gboolean is_app;
gboolean created_deploy_base = FALSE;
g_auto(GLnxLockFile) lock = GLNX_LOCK_FILE_INIT;
g_autoptr(GError) my_error = NULL;
context = g_option_context_new ("REPOSITORY NAME [BRANCH] - Install an application or runtime");
@@ -296,52 +260,14 @@ xdg_app_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro
return FALSE;
}
/* After we create the deploy base we must goto out on errors */
if (!opt_no_deploy)
{
if (!xdg_app_dir_lock (dir, &lock,
cancellable, error))
goto out;
if (!g_file_make_directory_with_parents (deploy_base, cancellable, error))
goto out;
created_deploy_base = TRUE;
if (!xdg_app_dir_set_origin (dir, ref, repository, cancellable, error))
goto out;
if (!xdg_app_dir_set_subpaths (dir, ref, (const char **)opt_subpaths,
cancellable, error))
goto out;
if (!xdg_app_dir_deploy (dir, ref, NULL, cancellable, error))
goto out;
if (is_app)
{
if (!xdg_app_dir_make_current_ref (dir, ref, cancellable, error))
goto out;
if (!xdg_app_dir_update_exports (dir, name, cancellable, error))
goto out;
}
glnx_release_lock_file (&lock);
if (!xdg_app_dir_deploy_install (dir, ref, repository, opt_subpaths,
cancellable, error))
return FALSE;
}
xdg_app_dir_cleanup_removed (dir, cancellable, NULL);
if (!xdg_app_dir_mark_changed (dir, error))
goto out;
ret = TRUE;
out:
if (created_deploy_base && !ret)
gs_shutil_rm_rf (deploy_base, cancellable, NULL);
return ret;
return TRUE;
}
gboolean
+75 -1
View File
@@ -2180,6 +2180,80 @@ xdg_app_dir_deploy (XdgAppDir *self,
return TRUE;
}
gboolean
xdg_app_dir_deploy_install (XdgAppDir *self,
const char *ref,
const char *origin,
char **subpaths,
GCancellable *cancellable,
GError **error)
{
g_auto(GLnxLockFile) lock = GLNX_LOCK_FILE_INIT;
g_autoptr(GFile) deploy_base = NULL;
gboolean created_deploy_base = FALSE;
gboolean ret = FALSE;
g_autoptr(GError) local_error = NULL;
g_auto(GStrv) ref_parts = g_strsplit (ref, "/", -1);
if (!xdg_app_dir_lock (self, &lock,
cancellable, error))
goto out;
deploy_base = xdg_app_dir_get_deploy_dir (self, ref);
if (!g_file_make_directory_with_parents (deploy_base, cancellable, &local_error))
{
if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
g_set_error (error,
G_IO_ERROR, G_IO_ERROR_EXISTS,
"%s branch %s already installed",
ref_parts[1], ref_parts[3]);
else
g_propagate_error (error, g_steal_pointer (&local_error));
goto out;
}
/* After we create the deploy base we must goto out on errors */
created_deploy_base = TRUE;
if (!xdg_app_dir_set_origin (self, ref, origin, cancellable, error))
goto out;
if (!xdg_app_dir_set_subpaths (self, ref, (const char **)subpaths,
cancellable, error))
goto out;
if (!xdg_app_dir_deploy (self, ref, NULL, cancellable, error))
goto out;
if (g_str_has_prefix (ref, "app/"))
{
if (!xdg_app_dir_make_current_ref (self, ref, cancellable, error))
goto out;
if (!xdg_app_dir_update_exports (self, ref_parts[1], cancellable, error))
goto out;
}
/* Release lock before doing possibly slow prune */
glnx_release_lock_file (&lock);
xdg_app_dir_cleanup_removed (self, cancellable, NULL);
if (!xdg_app_dir_mark_changed (self, error))
goto out;
ret = TRUE;
out:
if (created_deploy_base && !ret)
gs_shutil_rm_rf (deploy_base, cancellable, NULL);
return ret;
}
gboolean
xdg_app_dir_deploy_update (XdgAppDir *self,
const char *ref,
@@ -2224,7 +2298,7 @@ xdg_app_dir_deploy_update (XdgAppDir *self,
return FALSE;
}
/* Release lock before doing prune */
/* Release lock before doing possibly slow prune */
glnx_release_lock_file (&lock);
if (!xdg_app_dir_prune (self, cancellable, error))
+6
View File
@@ -211,6 +211,12 @@ gboolean xdg_app_dir_deploy_update (XdgAppDir *self,
const char *checksum,
GCancellable *cancellable,
GError **error);
gboolean xdg_app_dir_deploy_install (XdgAppDir *self,
const char *ref,
const char *origin,
char **subpaths,
GCancellable *cancellable,
GError **error);
gboolean xdg_app_dir_undeploy (XdgAppDir *self,
const char *ref,
const char *checksum,
+3 -80
View File
@@ -812,7 +812,6 @@ xdg_app_installation_install_bundle (XdgAppInstallation *self,
{
XdgAppInstallationPrivate *priv = xdg_app_installation_get_instance_private (self);
g_autofree char *ref = NULL;
gboolean created_deploy_base = FALSE;
gboolean added_remote = FALSE;
g_autoptr(GFile) deploy_base = NULL;
g_autoptr(XdgAppDir) dir_clone = NULL;
@@ -880,50 +879,12 @@ xdg_app_installation_install_bundle (XdgAppInstallation *self,
error))
goto out;
if (!xdg_app_dir_lock (dir_clone, &lock,
cancellable, error))
if (!xdg_app_dir_deploy_install (dir_clone, ref, remote, NULL, cancellable, error))
goto out;
if (!g_file_make_directory_with_parents (deploy_base, cancellable, &local_error))
{
if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
g_set_error (error,
XDG_APP_ERROR, XDG_APP_ERROR_ALREADY_INSTALLED,
"%s branch %s already installed", parts[1], parts[3]);
else
g_propagate_error (error, g_steal_pointer (&local_error));
goto out;
}
created_deploy_base = TRUE;
if (!xdg_app_dir_set_origin (dir_clone, ref, remote, cancellable, error))
goto out;
if (!xdg_app_dir_deploy (dir_clone, ref, NULL, cancellable, error))
goto out;
if (strcmp (parts[0], "app") == 0)
{
if (!xdg_app_dir_make_current_ref (dir_clone, ref, cancellable, error))
goto out;
if (!xdg_app_dir_update_exports (dir_clone, parts[1], cancellable, error))
goto out;
}
result = get_ref (self, ref, cancellable);
glnx_release_lock_file (&lock);
xdg_app_dir_cleanup_removed (dir_clone, cancellable, NULL);
if (!xdg_app_dir_mark_changed (dir_clone, error))
goto out;
out:
if (created_deploy_base && result == NULL)
gs_shutil_rm_rf (deploy_base, cancellable, NULL);
if (added_remote && result == NULL)
ostree_repo_remote_delete (xdg_app_dir_get_repo (priv->dir), remote, NULL, NULL);
@@ -962,7 +923,6 @@ xdg_app_installation_install (XdgAppInstallation *self,
{
XdgAppInstallationPrivate *priv = xdg_app_installation_get_instance_private (self);
g_autofree char *ref = NULL;
gboolean created_deploy_base = FALSE;
g_autoptr(GFile) deploy_base = NULL;
g_autoptr(XdgAppDir) dir_clone = NULL;
g_autoptr(GMainContext) main_context = NULL;
@@ -1002,53 +962,16 @@ xdg_app_installation_install (XdgAppInstallation *self,
ostree_progress, cancellable, error))
goto out;
if (!xdg_app_dir_lock (dir_clone, &lock,
cancellable, error))
if (!xdg_app_dir_deploy_install (dir_clone, ref, remote_name, NULL,
cancellable, error))
goto out;
if (!g_file_make_directory_with_parents (deploy_base, cancellable, &local_error))
{
if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS))
g_set_error (error,
XDG_APP_ERROR, XDG_APP_ERROR_ALREADY_INSTALLED,
"%s branch %s already installed", name, branch ? branch : "master");
else
g_propagate_error (error, g_steal_pointer (&local_error));
goto out;
}
created_deploy_base = TRUE;
if (!xdg_app_dir_set_origin (dir_clone, ref, remote_name, cancellable, error))
goto out;
if (!xdg_app_dir_deploy (dir_clone, ref, NULL, cancellable, error))
goto out;
if (kind == XDG_APP_REF_KIND_APP)
{
if (!xdg_app_dir_make_current_ref (dir_clone, ref, cancellable, error))
goto out;
if (!xdg_app_dir_update_exports (dir_clone, name, cancellable, error))
goto out;
}
result = get_ref (self, ref, cancellable);
glnx_release_lock_file (&lock);
xdg_app_dir_cleanup_removed (dir_clone, cancellable, NULL);
if (!xdg_app_dir_mark_changed (dir_clone, error))
goto out;
out:
if (main_context)
g_main_context_pop_thread_default (main_context);
if (created_deploy_base && result == NULL)
gs_shutil_rm_rf (deploy_base, cancellable, NULL);
if (ostree_progress)
ostree_async_progress_finish (ostree_progress);