From cb30e7ef4e9505437a323f43186d1cba33d764a2 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Fri, 11 Jan 2019 15:29:53 +0100 Subject: [PATCH] Add deploy refs for currently deployed commit. When we deploy e.g. app/org.foo.bar/x86_64/stable, then we also create a deploy/app/org.foo.bar/x86_64/stable ref pointing to the latest deployed commit. We also remove it when an app is uninstalled. This means that a prune operation will not delete objects that are deployed (which would not save any space anyway). This is nice because this can happen for instance when you flatpak update --no-deploy. Fixes https://github.com/flatpak/flatpak/issues/2085 Closes: #2563 Approved by: alexlarsson --- common/flatpak-dir.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index eb17b768..175492df 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -6846,6 +6846,22 @@ apply_extra_data (FlatpakDir *self, return TRUE; } +/* We create a deploy ref for the currently deployed version of all refs to avoid + deployed commits being pruned when e.g. we pull --no-deploy. */ +static gboolean +flatpak_dir_update_deploy_ref (FlatpakDir *self, + const char *ref, + const char *checksum, + GError **error) +{ + g_autofree char *deploy_ref = g_strconcat ("deploy/", ref, NULL); + + if (!ostree_repo_set_ref_immediate (self->repo, NULL, deploy_ref, checksum, NULL, error)) + return FALSE; + + return TRUE; +} + gboolean flatpak_dir_deploy (FlatpakDir *self, const char *origin, @@ -7280,6 +7296,9 @@ flatpak_dir_deploy (FlatpakDir *self, if (!flatpak_dir_set_active (self, ref, checkout_basename, cancellable, error)) return FALSE; + if (!flatpak_dir_update_deploy_ref (self, ref, checksum, error)) + return FALSE; + return TRUE; } @@ -8600,6 +8619,9 @@ flatpak_dir_uninstall (FlatpakDir *self, } } + if (!flatpak_dir_update_deploy_ref (self, ref, NULL, error)) + return FALSE; + if (!flatpak_dir_undeploy_all (self, ref, force_remove, &was_deployed, cancellable, error)) return FALSE;