mirror of
https://github.com/ostreedev/ostree.git
synced 2024-12-22 17:35:55 +03:00
add ObjectDetails-struct and use it in list_objects-function
This commit is contained in:
parent
81ea92566f
commit
2ab55beb98
@ -48,6 +48,8 @@ mod kernel_args;
|
|||||||
pub use crate::kernel_args::*;
|
pub use crate::kernel_args::*;
|
||||||
mod object_name;
|
mod object_name;
|
||||||
pub use crate::object_name::*;
|
pub use crate::object_name::*;
|
||||||
|
mod object_details;
|
||||||
|
pub use crate::object_details::*;
|
||||||
mod repo;
|
mod repo;
|
||||||
pub use crate::repo::*;
|
pub use crate::repo::*;
|
||||||
#[cfg(any(feature = "v2016_8", feature = "dox"))]
|
#[cfg(any(feature = "v2016_8", feature = "dox"))]
|
||||||
|
48
rust-bindings/rust/src/object_details.rs
Normal file
48
rust-bindings/rust/src/object_details.rs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
use glib;
|
||||||
|
use std::fmt::Display;
|
||||||
|
use std::fmt::Formatter;
|
||||||
|
use std::fmt::Error;
|
||||||
|
|
||||||
|
/// Details of an object in an OSTree repo. It contains information about if
|
||||||
|
/// the object is "loose", and contains a list of pack file checksums in which
|
||||||
|
/// this object appears.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ObjectDetails {
|
||||||
|
loose: bool,
|
||||||
|
object_appearances: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectDetails {
|
||||||
|
/// Create a new `ObjectDetails` from a serialized representation.
|
||||||
|
pub fn new_from_variant(variant: glib::Variant) -> Option<ObjectDetails> {
|
||||||
|
let deserialize = variant.get::<(bool, Vec<String>)>()?;
|
||||||
|
Some(ObjectDetails {
|
||||||
|
loose: deserialize.0,
|
||||||
|
object_appearances: deserialize.1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// is object available "loose"
|
||||||
|
pub fn is_loose(&self) -> bool {
|
||||||
|
self.loose
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Provide list of pack file checksums in which the object appears
|
||||||
|
pub fn appearances(&self) -> &Vec<String> {
|
||||||
|
&self.object_appearances
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Format this `ObjectDetails` as a string.
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
format!("Object is {} loose and appears in {} checksums",
|
||||||
|
if self.loose {"available"} else {"not available"},
|
||||||
|
self.object_appearances.len() )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for ObjectDetails{
|
||||||
|
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||||
|
write!(f, "{}", self.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
#[cfg(any(feature = "v2016_4", feature = "dox"))]
|
#[cfg(any(feature = "v2016_4", feature = "dox"))]
|
||||||
use crate::RepoListRefsExtFlags;
|
use crate::RepoListRefsExtFlags;
|
||||||
use crate::{Checksum, ObjectName, ObjectType, Repo, RepoTransactionStats};
|
use crate::{Checksum, ObjectName, ObjectDetails, ObjectType, Repo, RepoTransactionStats};
|
||||||
use ffi;
|
use ffi;
|
||||||
use ffi::OstreeRepoListObjectsFlags;
|
use ffi::OstreeRepoListObjectsFlags;
|
||||||
use glib::ffi as glib_sys;
|
use glib::ffi as glib_sys;
|
||||||
@ -31,9 +31,9 @@ unsafe extern "C" fn read_variant_object_map(
|
|||||||
) {
|
) {
|
||||||
let key: glib::Variant = from_glib_none(key as *const glib_sys::GVariant);
|
let key: glib::Variant = from_glib_none(key as *const glib_sys::GVariant);
|
||||||
let value: glib::Variant = from_glib_none(value as *const glib_sys::GVariant);
|
let value: glib::Variant = from_glib_none(value as *const glib_sys::GVariant);
|
||||||
if let Some(insert) = value.get::<(bool, Vec<String>)>() {
|
let set: &mut HashMap<ObjectName, ObjectDetails> = &mut *(hash_set as *mut HashMap<ObjectName, ObjectDetails>);
|
||||||
let set: &mut HashMap<ObjectName, (bool, Vec<String>)> = &mut *(hash_set as *mut HashMap<ObjectName, (bool, Vec<String>)>);
|
if let Some(details) = ObjectDetails::new_from_variant(value) {
|
||||||
set.insert(ObjectName::new_from_variant(key), insert);
|
set.insert(ObjectName::new_from_variant(key), details);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,12 +48,12 @@ unsafe fn from_glib_container_variant_set(ptr: *mut glib_sys::GHashTable) -> Has
|
|||||||
set
|
set
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn from_glib_container_variant_map(ptr: *mut glib_sys::GHashTable) -> HashMap<ObjectName, (bool, Vec<String>)> {
|
unsafe fn from_glib_container_variant_map(ptr: *mut glib_sys::GHashTable) -> HashMap<ObjectName, ObjectDetails> {
|
||||||
let mut set = HashMap::new();
|
let mut set = HashMap::new();
|
||||||
glib_sys::g_hash_table_foreach(
|
glib_sys::g_hash_table_foreach(
|
||||||
ptr,
|
ptr,
|
||||||
Some(read_variant_object_map),
|
Some(read_variant_object_map),
|
||||||
&mut set as *mut HashMap<ObjectName, (bool, Vec<String>)> as *mut _,
|
&mut set as *mut HashMap<ObjectName, ObjectDetails> as *mut _,
|
||||||
);
|
);
|
||||||
glib_sys::g_hash_table_unref(ptr);
|
glib_sys::g_hash_table_unref(ptr);
|
||||||
set
|
set
|
||||||
@ -177,7 +177,7 @@ impl Repo {
|
|||||||
&self,
|
&self,
|
||||||
flags: OstreeRepoListObjectsFlags,
|
flags: OstreeRepoListObjectsFlags,
|
||||||
cancellable: Option<&P>,
|
cancellable: Option<&P>,
|
||||||
) -> Result<HashMap<ObjectName, (bool, Vec<String>)>, Error> {
|
) -> Result<HashMap<ObjectName, ObjectDetails>, Error> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut error = ptr::null_mut();
|
let mut error = ptr::null_mut();
|
||||||
let mut hashtable = ptr::null_mut();
|
let mut hashtable = ptr::null_mut();
|
||||||
|
Loading…
Reference in New Issue
Block a user