src: add support for write_deployments_with_options

This commit is contained in:
Felix Krull 2020-08-26 10:13:01 +02:00 committed by Colin Walters
parent f45bfa2c5a
commit f3b0bbe64c
6 changed files with 81 additions and 7 deletions

View File

@ -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"

View File

@ -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<ostree_sys::OstreeSysroot, SysrootClass>);
@ -356,10 +358,14 @@ impl Sysroot {
}
}
//#[cfg(any(feature = "v2017_4", feature = "dox"))]
//pub fn write_deployments_with_options<P: IsA<gio::Cancellable>>(&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<P: IsA<gio::Cancellable>>(&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<P: IsA<gio::Cancellable>>(&self, deployment: &Deployment, new_origin: Option<&glib::KeyFile>, cancellable: Option<&P>) -> Result<(), glib::Error> {
unsafe {

View File

@ -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)

View File

@ -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)]

View File

@ -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<OstreeSysrootWriteDeploymentsOpts>;
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::<OstreeSysrootWriteDeploymentsOpts>() });
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);
}
}
}

View File

@ -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)