sysroot: Add ostree_sysroot_prepare_cleanup()
New public function works like ostree_sysroot_cleanup() EXCEPT FOR pruning the repository. Under the hood, add _ostree_sysroot_piecemeal_cleanup() which takes flags to better control what files are cleaned up. Both public cleanup functions are now wrappers for _ostree_sysroot_piecemeal_cleanup() with different flags.
This commit is contained in:
parent
fd6c572c42
commit
b0bd16ec11
|
|
@ -386,6 +386,7 @@ ostree_sysroot_get_booted_deployment
|
||||||
ostree_sysroot_get_deployment_directory
|
ostree_sysroot_get_deployment_directory
|
||||||
ostree_sysroot_get_deployment_origin_path
|
ostree_sysroot_get_deployment_origin_path
|
||||||
ostree_sysroot_cleanup
|
ostree_sysroot_cleanup
|
||||||
|
ostree_sysroot_prepare_cleanup
|
||||||
ostree_sysroot_get_repo
|
ostree_sysroot_get_repo
|
||||||
ostree_sysroot_deployment_set_kargs
|
ostree_sysroot_deployment_set_kargs
|
||||||
ostree_sysroot_write_deployments
|
ostree_sysroot_write_deployments
|
||||||
|
|
|
||||||
|
|
@ -425,20 +425,18 @@ cleanup_ref_prefix (OstreeRepo *repo,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
generate_deployment_refs_and_prune (OstreeSysroot *self,
|
generate_deployment_refs (OstreeSysroot *self,
|
||||||
OstreeRepo *repo,
|
OstreeRepo *repo,
|
||||||
int bootversion,
|
int bootversion,
|
||||||
int subbootversion,
|
int subbootversion,
|
||||||
GPtrArray *deployments,
|
GPtrArray *deployments,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
int cleanup_bootversion;
|
int cleanup_bootversion;
|
||||||
int cleanup_subbootversion;
|
int cleanup_subbootversion;
|
||||||
guint i;
|
guint i;
|
||||||
gint n_objects_total, n_objects_pruned;
|
|
||||||
guint64 freed_space;
|
|
||||||
|
|
||||||
cleanup_bootversion = (bootversion == 0) ? 1 : 0;
|
cleanup_bootversion = (bootversion == 0) ? 1 : 0;
|
||||||
cleanup_subbootversion = (subbootversion == 0) ? 1 : 0;
|
cleanup_subbootversion = (subbootversion == 0) ? 1 : 0;
|
||||||
|
|
@ -471,10 +469,27 @@ generate_deployment_refs_and_prune (OstreeSysroot *self,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
ostree_repo_abort_transaction (repo, cancellable, NULL);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
prune_repo (OstreeRepo *repo,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gint n_objects_total;
|
||||||
|
gint n_objects_pruned;
|
||||||
|
guint64 freed_space;
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
if (!ostree_repo_prune (repo, OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY, 0,
|
if (!ostree_repo_prune (repo, OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY, 0,
|
||||||
&n_objects_total, &n_objects_pruned, &freed_space,
|
&n_objects_total, &n_objects_pruned, &freed_space,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (freed_space > 0)
|
if (freed_space > 0)
|
||||||
{
|
{
|
||||||
char *freed_space_str = g_format_size_full (freed_space, 0);
|
char *freed_space_str = g_format_size_full (freed_space, 0);
|
||||||
|
|
@ -482,11 +497,11 @@ generate_deployment_refs_and_prune (OstreeSysroot *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
|
||||||
ostree_repo_abort_transaction (repo, cancellable, NULL);
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ostree_sysroot_cleanup:
|
* ostree_sysroot_cleanup:
|
||||||
* @self: Sysroot
|
* @self: Sysroot
|
||||||
|
|
@ -500,27 +515,78 @@ gboolean
|
||||||
ostree_sysroot_cleanup (OstreeSysroot *self,
|
ostree_sysroot_cleanup (OstreeSysroot *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
|
{
|
||||||
|
OstreeSysrootCleanupFlags flags;
|
||||||
|
|
||||||
|
/* Do everything. */
|
||||||
|
flags = OSTREE_SYSROOT_CLEANUP_ALL;
|
||||||
|
|
||||||
|
return _ostree_sysroot_piecemeal_cleanup (self, flags, cancellable, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ostree_sysroot_prepare_cleanup:
|
||||||
|
* @self: Sysroot
|
||||||
|
* @cancellable: Cancellable
|
||||||
|
* @error: Error
|
||||||
|
*
|
||||||
|
* Like ostree_sysroot_cleanup() in that it cleans up incomplete deployments
|
||||||
|
* and old boot versions, but does NOT prune the repository.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
ostree_sysroot_prepare_cleanup (OstreeSysroot *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
OstreeSysrootCleanupFlags flags;
|
||||||
|
|
||||||
|
/* Do everything EXCEPT pruning the repository. */
|
||||||
|
flags = OSTREE_SYSROOT_CLEANUP_ALL & ~OSTREE_SYSROOT_CLEANUP_PRUNE_REPO;
|
||||||
|
|
||||||
|
return _ostree_sysroot_piecemeal_cleanup (self, flags, cancellable, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_ostree_sysroot_piecemeal_cleanup (OstreeSysroot *self,
|
||||||
|
OstreeSysrootCleanupFlags flags,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
glnx_unref_object OstreeRepo *repo = NULL;
|
glnx_unref_object OstreeRepo *repo = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (OSTREE_IS_SYSROOT (self), FALSE);
|
||||||
g_return_val_if_fail (self->loaded, FALSE);
|
g_return_val_if_fail (self->loaded, FALSE);
|
||||||
|
|
||||||
if (!cleanup_other_bootversions (self, cancellable, error))
|
if (flags & OSTREE_SYSROOT_CLEANUP_BOOTVERSIONS)
|
||||||
goto out;
|
{
|
||||||
|
if (!cleanup_other_bootversions (self, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (!cleanup_old_deployments (self, cancellable, error))
|
if (flags & OSTREE_SYSROOT_CLEANUP_DEPLOYMENTS)
|
||||||
goto out;
|
{
|
||||||
|
if (!cleanup_old_deployments (self, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (self->deployments->len > 0)
|
if (self->deployments->len > 0)
|
||||||
{
|
{
|
||||||
if (!ostree_sysroot_get_repo (self, &repo, cancellable, error))
|
if (!ostree_sysroot_get_repo (self, &repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!generate_deployment_refs_and_prune (self, repo, self->bootversion,
|
if (!generate_deployment_refs (self, repo,
|
||||||
self->subbootversion, self->deployments,
|
self->bootversion,
|
||||||
cancellable, error))
|
self->subbootversion,
|
||||||
|
self->deployments,
|
||||||
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
if (flags & OSTREE_SYSROOT_CLEANUP_PRUNE_REPO)
|
||||||
|
{
|
||||||
|
if (!prune_repo (repo, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
|
||||||
|
|
@ -489,6 +489,9 @@ checkout_deployment_tree (OstreeSysroot *sysroot,
|
||||||
if (!glnx_opendirat (sysroot->sysroot_fd, osdeploy_path, TRUE, &osdeploy_dfd, error))
|
if (!glnx_opendirat (sysroot->sysroot_fd, osdeploy_path, TRUE, &osdeploy_dfd, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
if (!glnx_shutil_rm_rf_at (osdeploy_dfd, checkout_target_name, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (!ostree_repo_checkout_tree_at (repo, &checkout_opts, osdeploy_dfd,
|
if (!ostree_repo_checkout_tree_at (repo, &checkout_opts, osdeploy_dfd,
|
||||||
checkout_target_name, csum,
|
checkout_target_name, csum,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
|
|
|
||||||
|
|
@ -90,4 +90,16 @@ gboolean _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
OSTREE_SYSROOT_CLEANUP_BOOTVERSIONS = 1 << 0,
|
||||||
|
OSTREE_SYSROOT_CLEANUP_DEPLOYMENTS = 1 << 1,
|
||||||
|
OSTREE_SYSROOT_CLEANUP_PRUNE_REPO = 1 << 2,
|
||||||
|
OSTREE_SYSROOT_CLEANUP_ALL = 0xffff
|
||||||
|
} OstreeSysrootCleanupFlags;
|
||||||
|
|
||||||
|
gboolean _ostree_sysroot_piecemeal_cleanup (OstreeSysroot *sysroot,
|
||||||
|
OstreeSysrootCleanupFlags flags,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,10 @@ gboolean ostree_sysroot_cleanup (OstreeSysroot *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
gboolean ostree_sysroot_prepare_cleanup (OstreeSysroot *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
gboolean ostree_sysroot_write_origin_file (OstreeSysroot *sysroot,
|
gboolean ostree_sysroot_write_origin_file (OstreeSysroot *sysroot,
|
||||||
OstreeDeployment *deployment,
|
OstreeDeployment *deployment,
|
||||||
GKeyFile *new_origin,
|
GKeyFile *new_origin,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue