libpriv: Bridge print_treepkg_diff_from_sysroot_path()

This will be necessary for Rust-based client commands to be able to do
the regular "post-deployment package diff".
This commit is contained in:
Jonathan Lebon 2021-04-27 16:05:40 -04:00 committed by Colin Walters
parent 0474d40138
commit c095b97bf3
9 changed files with 62 additions and 37 deletions

View File

@ -449,6 +449,25 @@ pub mod ffi {
fn print(&self);
}
// https://cxx.rs/shared.html#extern-enums
enum RpmOstreeDiffPrintFormat {
RPMOSTREE_DIFF_PRINT_FORMAT_SUMMARY,
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_ALIGNED,
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE,
}
unsafe extern "C++" {
include!("rpmostree-libbuiltin.h");
include!("rpmostree-util.h");
type RpmOstreeDiffPrintFormat;
unsafe fn print_treepkg_diff_from_sysroot_path(
sysroot_path: &str,
format: RpmOstreeDiffPrintFormat,
max_key_len: u32,
cancellable: *mut GCancellable,
);
}
unsafe extern "C++" {
include!("rpmostree-output.h");
type Progress;

View File

@ -210,9 +210,8 @@ rpmostree_builtin_deploy (int argc,
/* do diff without dbus: https://github.com/projectatomic/rpm-ostree/pull/116 */
const char *sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy);
if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path,
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable, error))
return FALSE;
rpmostreecxx::print_treepkg_diff_from_sysroot_path (rust::Str(sysroot_path),
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable);
g_print ("Run \"systemctl reboot\" to start a reboot\n");
}

View File

@ -824,9 +824,8 @@ print_one_deployment (RPMOSTreeSysroot *sysroot_proxy,
{
/* No cached update, but we can still print a diff summary */
const char *sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy);
if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path, diff_format,
max_key_len, NULL, error))
return FALSE;
rpmostreecxx::print_treepkg_diff_from_sysroot_path (rust::Str(sysroot_path), diff_format,
max_key_len, NULL);
}
/* print base overrides before overlays */

View File

@ -245,9 +245,8 @@ rpmostree_builtin_upgrade (int argc,
/* do diff without dbus: https://github.com/projectatomic/rpm-ostree/pull/116 */
const char *sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy);
if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path,
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable, error))
return FALSE;
rpmostreecxx::print_treepkg_diff_from_sysroot_path (rust::Str(sysroot_path),
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable);
g_print ("Run \"systemctl reboot\" to start a reboot\n");
}

View File

@ -939,9 +939,8 @@ rpmostree_transaction_client_run (RpmOstreeCommandInvocation *invocation,
{
/* do diff without dbus: https://github.com/projectatomic/rpm-ostree/pull/116 */
const char *sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy);
if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path,
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable, error))
return FALSE;
rpmostreecxx::print_treepkg_diff_from_sysroot_path (rust::Str(sysroot_path),
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable);
}
g_print ("Run \"systemctl reboot\" to start a reboot\n");

View File

@ -83,18 +83,21 @@ rpmostree_has_new_default_deployment (RPMOSTreeOS *os_proxy,
return !g_str_equal (previous_id, new_id);
}
namespace rpmostreecxx {
/* Print the diff between the booted and pending deployments */
gboolean
rpmostree_print_treepkg_diff_from_sysroot_path (const gchar *sysroot_path,
RpmOstreeDiffPrintFormat format,
guint max_key_len,
GCancellable *cancellable,
GError **error)
void
print_treepkg_diff_from_sysroot_path (rust::Str sysroot_path,
RpmOstreeDiffPrintFormat format,
guint32 max_key_len,
GCancellable *cancellable)
{
g_autoptr(GFile) sysroot_file = g_file_new_for_path (sysroot_path);
g_autoptr(GError) local_error = NULL;
g_autofree char *sysroot_cpath = g_strndup (sysroot_path.data(), sysroot_path.length());
g_autoptr(GFile) sysroot_file = g_file_new_for_path (sysroot_cpath);
g_autoptr(OstreeSysroot) sysroot = ostree_sysroot_new (sysroot_file);
if (!ostree_sysroot_load (sysroot, cancellable, error))
return FALSE;
if (!ostree_sysroot_load (sysroot, cancellable, &local_error))
util::throw_gerror(local_error);
g_autoptr(GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot);
g_assert_cmpuint (deployments->len, >, 1);
@ -103,11 +106,11 @@ rpmostree_print_treepkg_diff_from_sysroot_path (const gchar *sysroot_path,
OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);
if (!booted_deployment || ostree_deployment_equal (booted_deployment, new_deployment))
return TRUE;
return;
g_autoptr(OstreeRepo) repo = NULL;
if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
return FALSE;
if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, &local_error))
util::throw_gerror(local_error);
const char *from_rev = ostree_deployment_get_csum (booted_deployment);
const char *to_rev = ostree_deployment_get_csum (new_deployment);
@ -118,14 +121,15 @@ rpmostree_print_treepkg_diff_from_sysroot_path (const gchar *sysroot_path,
g_autoptr(GPtrArray) modified_new = NULL;
if (!rpm_ostree_db_diff (repo, from_rev, to_rev,
&removed, &added, &modified_old, &modified_new,
cancellable, error))
return FALSE;
cancellable, &local_error))
util::throw_gerror(local_error);
rpmostree_diff_print_formatted (format, NULL, max_key_len,
removed, added, modified_old, modified_new);
return TRUE;
}
} /* namespace */
void
rpmostree_print_timestamp_version (const char *version_string,
const char *timestamp_string,

View File

@ -63,12 +63,14 @@ gboolean
rpmostree_has_new_default_deployment (RPMOSTreeOS *os_proxy,
GVariant *previous_deployment);
gboolean
rpmostree_print_treepkg_diff_from_sysroot_path (const gchar *sysroot_path,
RpmOstreeDiffPrintFormat format,
guint max_key_len,
GCancellable *cancellable,
GError **error);
namespace rpmostreecxx {
void
print_treepkg_diff_from_sysroot_path (rust::Str sysroot_path,
RpmOstreeDiffPrintFormat format,
guint32 max_key_len,
GCancellable *cancellable);
}
void
rpmostree_print_timestamp_version (const char *version_string,

View File

@ -123,9 +123,8 @@ handle_override (RPMOSTreeSysroot *sysroot_proxy,
return TRUE;
const char *sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy);
if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path,
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable, error))
return FALSE;
rpmostreecxx::print_treepkg_diff_from_sysroot_path (rust::Str(sysroot_path),
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_MULTILINE, 0, cancellable);
if (override_replace || override_remove)
g_print ("Use \"rpm-ostree override reset\" to undo overrides\n");

View File

@ -174,7 +174,8 @@ rpmostree_generate_diff_summary (guint upgraded,
guint removed,
guint added);
typedef enum {
// note this enum is shared with Rust via the cxxbridge
typedef enum : std::uint8_t {
RPMOSTREE_DIFF_PRINT_FORMAT_SUMMARY, /* Diff: 1 upgraded, 2 downgraded, 3 removed, 4 added */
RPMOSTREE_DIFF_PRINT_FORMAT_FULL_ALIGNED, /* Upgraded: ...
...
@ -188,6 +189,10 @@ typedef enum {
... */
} RpmOstreeDiffPrintFormat;
namespace rpmostreecxx {
using RpmOstreeDiffPrintFormat = ::RpmOstreeDiffPrintFormat;
}
void
rpmostree_diff_print_formatted (RpmOstreeDiffPrintFormat format,
const char *prefix,