Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewarmtemp committed Jul 17, 2023
1 parent f2d63d3 commit 6bbbf61
Show file tree
Hide file tree
Showing 11 changed files with 586 additions and 46 deletions.
36 changes: 29 additions & 7 deletions src/app/rpmostree-builtin-upgrade.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,43 @@ rpmostree_builtin_upgrade (int argc, char **argv, RpmOstreeCommandInvocation *in
g_print ("Note: --check and --preview may be unreliable. See "
"https://github.com/coreos/rpm-ostree/issues/1579\n");
g_autoptr (GVariant) cached_update = NULL;
if (rpmostree_os_get_has_cached_update_rpm_diff (os_proxy))
if (rpmostree_os_get_has_cached_update_rpm_diff (os_proxy)) {
g_print ("yes rpm diff.\n");
cached_update = rpmostree_os_dup_cached_update (os_proxy);
}

if (!cached_update)
{
g_print ("No updates available.\n");
invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED;
}
else
g_autoptr (GVariant) cached_update_container = NULL;
if (rpmostree_os_get_has_cached_update_manifest_diff (os_proxy)) {
g_print ("yes container diff.\n");
cached_update_container = rpmostree_os_dup_cached_update (os_proxy);
}

g_print ("exit diff checks\n");

// cached_update = rpmostree_os_dup_cached_update (os_proxy);

if (cached_update)
{
/* preview --> verbose (i.e. we want the diff) */
// if (!rpmostree_print_cached_update (cached_update, opt_preview, FALSE, cancellable,
// error))
// return FALSE;

if (!rpmostree_print_cached_update (cached_update, opt_preview, FALSE, cancellable,
error))
return FALSE;
}
else if (cached_update_container) {
if (!rpmostree_print_cached_update_container (cached_update, opt_preview, FALSE, cancellable,
error))
return FALSE;
}
else
{
g_print ("No updates available.\n");
invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED;
}

}
else if (!opt_reboot)
{
Expand Down
86 changes: 86 additions & 0 deletions src/app/rpmostree-clientlib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,92 @@ rpmostree_print_cached_update (GVariant *cached_update, gboolean verbose,
return TRUE;
}

gboolean
rpmostree_print_cached_update_container (GVariant *cached_update, gboolean verbose,
gboolean verbose_advisories, GCancellable *cancellable,
GError **error)
{
GLNX_AUTO_PREFIX_ERROR ("Retrieving cached update", error);

g_auto (GVariantDict) dict;
g_variant_dict_init (&dict, cached_update);

/* let's just extract 📤 all the info ahead of time */

g_autoptr (GVariant) manifest_diff
= g_variant_dict_lookup_value (&dict, "manifest-diff", G_VARIANT_TYPE ("a{sv}"));

g_autoptr (GVariantIter) iter1 = NULL;
g_variant_get (manifest_diff, "a{sv}", &iter1);

if (!manifest_diff)
g_print("WE Failed");

const gchar *key;
const gchar *value;
while (g_variant_iter_loop (iter1, "{sv}", &key, &value))
{
g_print("%s", key);
}

// g_auto (GVariantDict) rpm_diff_dict;
// g_variant_dict_init (&rpm_diff_dict, rpm_diff);

// g_autoptr (GVariant) total
// = g_variant_dict_lookup_value (&rpm_diff_dict, "total_size", G_VARIANT_TYPE ("s"));
// if (!total)
// g_print("WE Failed2");
// return FALSE;

// g_autoptr (GVariant) total_size = _rpmostree_vardict_lookup_value_required (
// &rpm_diff_dict, "total_size", RPMOSTREE_DIFF_MODIFIED_GVARIANT_FORMAT, error);
// if (!total_size)
// return FALSE;

// g_autoptr (GVariant) total_removed = _rpmostree_vardict_lookup_value_required (
// &rpm_diff_dict, "total_removed", RPMOSTREE_DIFF_MODIFIED_GVARIANT_FORMAT, error);
// if (!total_removed)
// return FALSE;

// g_autoptr (GVariant) removed_size = _rpmostree_vardict_lookup_value_required (
// &rpm_diff_dict, "removed_size", RPMOSTREE_DIFF_MODIFIED_GVARIANT_FORMAT, error);
// if (!removed_size)
// return FALSE;

// g_autoptr (GVariant) total_added = _rpmostree_vardict_lookup_value_required (
// &rpm_diff_dict, "total_added", RPMOSTREE_DIFF_MODIFIED_GVARIANT_FORMAT, error);
// if (!total_added)
// return FALSE;

// g_autoptr (GVariant) added_size = _rpmostree_vardict_lookup_value_required (
// &rpm_diff_dict, "added_size", RPMOSTREE_DIFF_MODIFIED_GVARIANT_FORMAT, error);
// if (!added_size)
// return FALSE;

// const gchar *tmp1;
// const gchar *tmp2;
// const gchar *tmp3;
// const gchar *tmp4;
// const gchar *tmp5;
// const gchar *tmp6;

// g_variant_get (total, "s", &tmp1);
// g_variant_get (total_size, "s", &tmp2);
// g_variant_get (total_removed, "s", &tmp3);
// g_variant_get (removed_size, "s", &tmp4);
// g_variant_get (total_added, "s", &tmp5);
// g_variant_get (added_size, "s", &tmp6);

// g_print("%s", tmp1);
// g_print("%s", tmp2);
// g_print("%s", tmp3);
// g_print("%s", tmp4);
// g_print("%s", tmp5);
// g_print("%s", tmp6);

return TRUE;
}

/* Query systemd for systemd unit's object path using method_name provided with
* parameters. The reply_type of method_name must be G_VARIANT_TYPE_TUPLE. */
gboolean
Expand Down
4 changes: 4 additions & 0 deletions src/app/rpmostree-clientlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ gboolean rpmostree_print_cached_update (GVariant *cached_update, gboolean verbos
gboolean verbose_advisories, GCancellable *cancellable,
GError **error);

gboolean rpmostree_print_cached_update_container (GVariant *cached_update, gboolean verbose,
gboolean verbose_advisories, GCancellable *cancellable,
GError **error);

void rpmostree_print_advisories (GVariant *advisories, gboolean verbose, guint max_key_len);

gboolean get_sd_unit_objpath (GDBusConnection *connection, const char *method_name,
Expand Down
1 change: 1 addition & 0 deletions src/daemon/org.projectatomic.rpmostree1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QVariantMap"/>
</property>
<property name="HasCachedUpdateRpmDiff" type="b" access="read"/>
<property name="HasCachedUpdateManifestDiff" type="b" access="read"/>

<!-- Available options:
"mode" (type 's')
Expand Down
172 changes: 172 additions & 0 deletions src/daemon/rpmostree-sysroot-upgrader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include "rpmostree-sysroot-upgrader.h"
#include "rpmostreed-daemon.h"
#include "rpmostreed-deployment-utils.h"
// #include "rpmostreed-sysroot.cxx"
#include "rpmostreed-transaction-types.cxx"
// #include "rpmostreed-os.cxx"

#include "ostree-repo.h"

Expand Down Expand Up @@ -401,6 +404,92 @@ rpmostree_sysroot_upgrader_get_sack (RpmOstreeSysrootUpgrader *self, GError **er
return self->rpmmd_sack;
}

static gboolean
refresh_cached_update_impl (RpmostreedOS *self, GVariant **out_cached_update, GError **error)
{
g_autoptr (GVariant) cached_update = NULL;

/* if we're not booted into our OS, don't look at cache; it's for another OS interface */
const char *osname = rpmostree_os_get_name (RPMOSTREE_OS (self));

rpmostree_output_message ("%s", osname);

OstreeSysroot *sysroot = rpmostreed_sysroot_get_root (rpmostreed_sysroot_get ());
OstreeDeployment *booted = ostree_sysroot_get_booted_deployment (sysroot);
if (!booted || !g_str_equal (osname, ostree_deployment_get_osname (booted))) {
rpmostree_output_message ("exit 1");
return TRUE; /* Note early return */
}

glnx_autofd int fd = -1;
g_autoptr (GError) local_error = NULL;
rpmostree_output_message ("%s", RPMOSTREE_AUTOUPDATES_CACHE_FILE);
rpmostree_output_message ("%d", AT_FDCWD);
if (!glnx_openat_rdonly (AT_FDCWD, RPMOSTREE_AUTOUPDATES_CACHE_FILE, TRUE, &fd, &local_error))
{
if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
return g_propagate_error (error, util::move_nullify (local_error)), FALSE;
rpmostree_output_message ("exit 2");
return TRUE; /* Note early return */
}

/* sanity check there isn't something fishy going on before even reading it in */
struct stat stbuf;
if (!glnx_fstat (fd, &stbuf, error))
return FALSE;

if (!rpmostree_check_size_within_limit (stbuf.st_size, OSTREE_MAX_METADATA_SIZE,
RPMOSTREE_AUTOUPDATES_CACHE_FILE, error))
return FALSE;

g_autoptr (GBytes) data = glnx_fd_readall_bytes (fd, NULL, error);
if (!data)
return FALSE;

cached_update
= g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE_VARDICT, data, FALSE));

/* check if cache is still valid -- see rpmostreed_update_generate_variant() */
g_auto (GVariantDict) dict;
g_variant_dict_init (&dict, cached_update);
auto state = static_cast<const char *> (vardict_lookup_ptr (&dict, "update-sha256", "&s"));
if (g_strcmp0 (state, ostree_deployment_get_csum (booted)) != 0)
{
sd_journal_print (LOG_INFO, "Deleting outdated cached update for OS '%s'", osname);
g_clear_pointer (&cached_update, (GDestroyNotify)g_variant_unref);
if (!glnx_unlinkat (AT_FDCWD, RPMOSTREE_AUTOUPDATES_CACHE_FILE, 0, error))
return FALSE;
}

*out_cached_update = util::move_nullify (cached_update);
rpmostree_output_message ("exit 3");
return TRUE;
}

static gboolean
refresh_cached_update (RpmostreedOS *self, GError **error)
{
g_autoptr (GVariant) cached_update = NULL;
if (!refresh_cached_update_impl (self, &cached_update, error)) {
rpmostree_output_message ("fail_cached_update_func");
return FALSE;
}

rpmostree_output_message ("pass_cached_update_func");

if (cached_update != NULL) {
rpmostree_output_message ("yes update");
}
else {
rpmostree_output_message ("no update");
}

rpmostree_os_set_cached_update (RPMOSTREE_OS (self), cached_update);
rpmostree_os_set_has_cached_update_rpm_diff (RPMOSTREE_OS (self), cached_update != NULL);
rpmostree_os_set_has_cached_update_manifest_diff (RPMOSTREE_OS (self), cached_update != NULL);
return TRUE;
}

/*
* Like ostree_sysroot_upgrader_pull(), but also handles the `baserefspec` we
* use when doing layered packages.
Expand Down Expand Up @@ -448,6 +537,89 @@ rpmostree_sysroot_upgrader_pull_base (RpmOstreeSysrootUpgrader *self, const char
error);

rpmostree_output_message ("%s", res.c_str ());

auto obj = (RpmostreedOS *)g_object_new (RPMOSTREED_TYPE_OS, "name", self->osname, NULL);
g_autoptr (GError) local_error = NULL;
// if (!refresh_cached_update (obj, &local_error))
// {
// sd_journal_print (LOG_WARNING, "Failed to refresh CachedUpdate property: %s",
// local_error->message);

// }

g_autoptr (RpmOstreeSysrootUpgrader) upgrader = rpmostree_sysroot_upgrader_new (
self->sysroot, self->osname, (RpmOstreeSysrootUpgraderFlags)0, cancellable, error);
if (upgrader == NULL)
return FALSE;

g_autoptr (OstreeDeployment) new_deployment = NULL;
if (!rpmostree_sysroot_upgrader_deploy (upgrader, &new_deployment, cancellable, error))
return FALSE;

OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (self->sysroot);

g_autoptr (DnfSack) sack = NULL;
if (rpmostree_origin_has_packages (self->computed_origin))
{
if (!get_sack_for_booted (self->sysroot, self->repo, booted_deployment, &sack, cancellable, error))
return FALSE;
}

// if (!generate_update_variant (self->repo, booted_deployment, new_deployment, sack, cancellable, error))
// if (!generate_update_variant (self->repo, booted_deployment, NULL, NULL, TRUE, res.c_str (), cancellable, error))
// return FALSE;

// auto obj = (RpmostreedOS *)g_object_new (RPMOSTREED_TYPE_OS, "name", self->osname, NULL);
// g_autoptr (GError) local_error = NULL;
if (!refresh_cached_update (obj, &local_error))
{
sd_journal_print (LOG_WARNING, "BRUH: %s",
local_error->message);

}

if (!refresh_cached_update (obj, &local_error))
{
sd_journal_print (LOG_WARNING, "BRUH 22: %s",
local_error->message);

}

// glnx_autofd int fd = -1;
// rpmostree_output_message ("stage 1");
// // g_autoptr (GError) local_error = NULL;
// // rpmostree_output_message ("%s", RPMOSTREE_AUTOUPDATES_CACHE_FILE);

// // /* sanity check there isn't something fishy going on before even reading it in */
// // struct stat stbuf;
// // if (!glnx_fstat (fd, &stbuf, error))
// // return FALSE;

// // if (!rpmostree_check_size_within_limit (stbuf.st_size, OSTREE_MAX_METADATA_SIZE,
// // RPMOSTREE_AUTOUPDATES_CACHE_FILE, error))
// // return FALSE;

// g_autoptr (GBytes) data = glnx_fd_readall_bytes (fd, NULL, error);
// rpmostree_output_message ("stage 2");
// if (!data)
// return FALSE;
// rpmostree_output_message ("stage 3");

// g_autoptr (GVariant) cached_update = NULL;
// cached_update
// = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE_VARDICT, data, FALSE));
rpmostree_output_message ("pass");

g_autoptr (GVariantDict) dict = g_variant_dict_new (NULL);
// g_variant_dict_insert (dict, "ref-has-new-commit", "b", is_new_checksum);

g_autoptr (GPtrArray) removed = NULL;
g_autoptr (GPtrArray) added = NULL;
g_autoptr (GPtrArray) modified_old = NULL;
g_autoptr (GPtrArray) modified_new = NULL;



*out_changed = TRUE;
return TRUE;
}
Expand Down
Loading

0 comments on commit 6bbbf61

Please sign in to comment.