diff --git a/src/daemon/rpmostreed-os.c b/src/daemon/rpmostreed-os.c index bf795b0d..189cfc68 100644 --- a/src/daemon/rpmostreed-os.c +++ b/src/daemon/rpmostreed-os.c @@ -463,6 +463,20 @@ merge_compatible_txn (RpmostreedOS *self, return NULL; } +static gboolean +refresh_cached_update (RpmostreedOS*, GError **error); + +static void +on_auto_update_done (RpmostreedTransaction *transaction, RpmostreedOS *self) +{ + g_autoptr(GError) local_error = NULL; + if (!refresh_cached_update (self, &local_error)) + { + sd_journal_print (LOG_WARNING, "Failed to refresh CachedUpdate property: %s", + local_error->message); + } +} + static gboolean os_handle_download_update_rpm_diff (RPMOSTreeOS *interface, GDBusMethodInvocation *invocation) @@ -498,6 +512,11 @@ os_handle_download_update_rpm_diff (RPMOSTreeOS *interface, if (transaction == NULL) goto out; + /* Make sure we refresh CachedUpdate after the transaction. This normally happens + * automatically if new data was downloaded (through the repo mtime bump --> UPDATED + * signal), but we also want to do this even if the data was already present. */ + g_signal_connect (transaction, "closed", G_CALLBACK (on_auto_update_done), self); + rpmostreed_transaction_monitor_add (self->transaction_monitor, transaction); out: @@ -711,20 +730,6 @@ start_deployment_txn (GDBusMethodInvocation *invocation, cancellable, error); } -static gboolean -refresh_cached_update (RpmostreedOS*, GError **error); - -static void -on_auto_update_done (RpmostreedTransaction *transaction, RpmostreedOS *self) -{ - g_autoptr(GError) local_error = NULL; - if (!refresh_cached_update (self, &local_error)) - { - sd_journal_print (LOG_WARNING, "Failed to refresh CachedUpdate property: %s", - local_error->message); - } -} - typedef void (*InvocationCompleter)(RPMOSTreeOS*, GDBusMethodInvocation*, GUnixFDList*, diff --git a/src/daemon/rpmostreed-transaction-types.c b/src/daemon/rpmostreed-transaction-types.c index 76951526..f881b484 100644 --- a/src/daemon/rpmostreed-transaction-types.c +++ b/src/daemon/rpmostreed-transaction-types.c @@ -330,6 +330,17 @@ package_diff_transaction_execute (RpmostreedTransaction *transaction, rpmostree_output_message ("No change."); } + if (upgrading) + { + /* For backwards compatibility, we still need to make sure the CachedUpdate property + * is updated here. To do this, we cache to disk in libostree mode (no DnfSack), since + * that's all we updated here. This conflicts with auto-updates for now, though we + * need better test coverage before uniting those two paths. */ + OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot); + if (!generate_update_variant (repo, booted_deployment, NULL, cancellable, error)) + return FALSE; + } + return TRUE; } diff --git a/tests/vmcheck/test-cached-rpm-diffs.sh b/tests/vmcheck/test-cached-rpm-diffs.sh index 766b3b1c..f2dedee2 100755 --- a/tests/vmcheck/test-cached-rpm-diffs.sh +++ b/tests/vmcheck/test-cached-rpm-diffs.sh @@ -58,6 +58,33 @@ call_dbus() { -m org.projectatomic.rpmostree1.OS.$method "$@" } +if vm_cmd test -x /usr/bin/python3; then + py=python3 +else + py=python +fi + +run_transaction() { + method=$1; shift + sig=$1; shift + args=$1; shift + cur=$(vm_get_journal_cursor) + # use ansible for this so we don't have to think about hungry quote-eating ssh + vm_shell_inline < out.txt assert_file_has_content out.txt "<'vmcheck'>" assert_file_has_content out.txt "$deploy_csum" @@ -85,3 +112,9 @@ assert_file_has_content out.txt "pkg1" assert_file_has_content out.txt "pkg2" assert_file_has_content out.txt "pkg3" echo "ok GetCachedRebaseRpmDiff" + +# This is not a super realistic test since we don't actually download anything. +# Still it checks that we properly update the cache +run_transaction DownloadUpdateRpmDiff "" "" +vm_assert_status_jq '.["cached-update"]["version"] == "vUpdate"' +echo "ok DownloadUpdateRpmDiff"