From f3b0bbe64ceb4f68337c466f653d0d9f3135b3eb Mon Sep 17 00:00:00 2001 From: Felix Krull Date: Wed, 26 Aug 2020 10:13:01 +0200 Subject: [PATCH] src: add support for write_deployments_with_options --- rust-bindings/rust/conf/ostree.toml | 11 +++- rust-bindings/rust/src/auto/sysroot.rs | 14 +++-- rust-bindings/rust/src/auto/versions.txt | 2 +- rust-bindings/rust/src/lib.rs | 4 ++ .../src/sysroot_write_deployments_opts.rs | 55 +++++++++++++++++++ rust-bindings/rust/sys/src/auto/versions.txt | 2 +- 6 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 rust-bindings/rust/src/sysroot_write_deployments_opts.rs diff --git a/rust-bindings/rust/conf/ostree.toml b/rust-bindings/rust/conf/ostree.toml index 0458b8cf..a3fbdfea 100644 --- a/rust-bindings/rust/conf/ostree.toml +++ b/rust-bindings/rust/conf/ostree.toml @@ -50,7 +50,6 @@ generate = [ "OSTree.RepoResolveRevExtFlags", "OSTree.SePolicyRestoreconFlags", "OSTree.StaticDeltaGenerateOpt", - "OSTree.Sysroot", "OSTree.SysrootSimpleWriteDeploymentFlags", "OSTree.SysrootUpgrader", "OSTree.SysrootUpgraderFlags", @@ -83,6 +82,7 @@ manual = [ "OSTree.KernelArgs", "OSTree.RepoCheckoutAtOptions", "OSTree.RepoCheckoutFilter", + "OSTree.SysrootWriteDeploymentsOpts", ] ignore = [ @@ -199,6 +199,15 @@ status = "generate" pattern = "dummy_.+|ed25519_.+" ignore = true +[[object]] +name = "OSTree.Sysroot" +status = "generate" + [[object.function]] + name = "write_deployments_with_options" + [[object.function.parameter]] + name = "opts" + const = true + [[object]] name = "OSTree.*" status = "generate" diff --git a/rust-bindings/rust/src/auto/sysroot.rs b/rust-bindings/rust/src/auto/sysroot.rs index d5f1583d..9915cc19 100644 --- a/rust-bindings/rust/src/auto/sysroot.rs +++ b/rust-bindings/rust/src/auto/sysroot.rs @@ -31,6 +31,8 @@ use Deployment; use DeploymentUnlockedState; use Repo; use SysrootSimpleWriteDeploymentFlags; +#[cfg(any(feature = "v2017_4", feature = "dox"))] +use SysrootWriteDeploymentsOpts; glib_wrapper! { pub struct Sysroot(Object); @@ -356,10 +358,14 @@ impl Sysroot { } } - //#[cfg(any(feature = "v2017_4", feature = "dox"))] - //pub fn write_deployments_with_options>(&self, new_deployments: &[Deployment], opts: /*Ignored*/&mut SysrootWriteDeploymentsOpts, cancellable: Option<&P>) -> Result<(), glib::Error> { - // unsafe { TODO: call ostree_sys:ostree_sysroot_write_deployments_with_options() } - //} + #[cfg(any(feature = "v2017_4", feature = "dox"))] + pub fn write_deployments_with_options>(&self, new_deployments: &[Deployment], opts: &SysrootWriteDeploymentsOpts, cancellable: Option<&P>) -> Result<(), glib::Error> { + unsafe { + let mut error = ptr::null_mut(); + let _ = ostree_sys::ostree_sysroot_write_deployments_with_options(self.to_glib_none().0, new_deployments.to_glib_none().0, mut_override(opts.to_glib_none().0), cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error); + if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) } + } + } pub fn write_origin_file>(&self, deployment: &Deployment, new_origin: Option<&glib::KeyFile>, cancellable: Option<&P>) -> Result<(), glib::Error> { unsafe { diff --git a/rust-bindings/rust/src/auto/versions.txt b/rust-bindings/rust/src/auto/versions.txt index 7b36b436..b14e7670 100644 --- a/rust-bindings/rust/src/auto/versions.txt +++ b/rust-bindings/rust/src/auto/versions.txt @@ -1,2 +1,2 @@ Generated by gir (https://github.com/gtk-rs/gir @ 2d1ffab1) -from gir-files (https://github.com/gtk-rs/gir-files @ 203ae47) +from gir-files (https://github.com/gtk-rs/gir-files @ ac0d3c9) diff --git a/rust-bindings/rust/src/lib.rs b/rust-bindings/rust/src/lib.rs index 64f435cc..892bca77 100644 --- a/rust-bindings/rust/src/lib.rs +++ b/rust-bindings/rust/src/lib.rs @@ -53,6 +53,10 @@ pub use crate::se_policy::*; mod commit_sizes_entry; #[cfg(any(feature = "v2020_1", feature = "dox"))] pub use crate::commit_sizes_entry::*; +#[cfg(any(feature = "v2017_4", feature = "dox"))] +mod sysroot_write_deployments_opts; +#[cfg(any(feature = "v2017_4", feature = "dox"))] +pub use crate::sysroot_write_deployments_opts::*; // tests #[cfg(test)] diff --git a/rust-bindings/rust/src/sysroot_write_deployments_opts.rs b/rust-bindings/rust/src/sysroot_write_deployments_opts.rs new file mode 100644 index 00000000..9c053b20 --- /dev/null +++ b/rust-bindings/rust/src/sysroot_write_deployments_opts.rs @@ -0,0 +1,55 @@ +use glib::translate::*; +use ostree_sys::OstreeSysrootWriteDeploymentsOpts; + +pub struct SysrootWriteDeploymentsOpts { + pub do_postclean: bool, +} + +impl Default for SysrootWriteDeploymentsOpts { + fn default() -> Self { + SysrootWriteDeploymentsOpts { + do_postclean: false, + } + } +} + +impl<'a> ToGlibPtr<'a, *const OstreeSysrootWriteDeploymentsOpts> for SysrootWriteDeploymentsOpts { + type Storage = Box; + + fn to_glib_none(&'a self) -> Stash<*const OstreeSysrootWriteDeploymentsOpts, Self> { + // Creating this struct from zeroed memory is fine since it's `repr(C)` and only contains + // primitive types. + // The struct needs to be boxed so the pointer we return remains valid even as the Stash is + // moved around. + let mut options = + Box::new(unsafe { std::mem::zeroed::() }); + options.do_postclean = self.do_postclean.to_glib(); + Stash(options.as_ref(), options) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use glib_sys::{GFALSE, GTRUE}; + + #[test] + fn should_convert_default_options() { + let options = SysrootWriteDeploymentsOpts::default(); + let stash = options.to_glib_none(); + let ptr = stash.0; + unsafe { + assert_eq!((*ptr).do_postclean, GFALSE); + } + } + + #[test] + fn should_convert_non_default_options() { + let options = SysrootWriteDeploymentsOpts { do_postclean: true }; + let stash = options.to_glib_none(); + let ptr = stash.0; + unsafe { + assert_eq!((*ptr).do_postclean, GTRUE); + } + } +} diff --git a/rust-bindings/rust/sys/src/auto/versions.txt b/rust-bindings/rust/sys/src/auto/versions.txt index 7b36b436..b14e7670 100644 --- a/rust-bindings/rust/sys/src/auto/versions.txt +++ b/rust-bindings/rust/sys/src/auto/versions.txt @@ -1,2 +1,2 @@ Generated by gir (https://github.com/gtk-rs/gir @ 2d1ffab1) -from gir-files (https://github.com/gtk-rs/gir-files @ 203ae47) +from gir-files (https://github.com/gtk-rs/gir-files @ ac0d3c9)