update result type

This commit is contained in:
Manuel Stühn 2021-11-16 11:28:38 +01:00 committed by Colin Walters
parent f6c1e0cb82
commit 81ea92566f
2 changed files with 24 additions and 11 deletions

View File

@ -24,28 +24,41 @@ unsafe extern "C" fn read_variant_table(
set.insert(ObjectName::new_from_variant(value)); set.insert(ObjectName::new_from_variant(value));
} }
unsafe extern "C" fn read_variant_table_from_key( unsafe extern "C" fn read_variant_object_map(
key: glib_sys::gpointer, key: glib_sys::gpointer,
_value: glib_sys::gpointer, value: glib_sys::gpointer,
hash_set: glib_sys::gpointer, hash_set: glib_sys::gpointer,
) { ) {
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 set: &mut HashSet<ObjectName> = &mut *(hash_set as *mut HashSet<ObjectName>); let value: glib::Variant = from_glib_none(value as *const glib_sys::GVariant);
set.insert(ObjectName::new_from_variant(key)); if let Some(insert) = value.get::<(bool, Vec<String>)>() {
let set: &mut HashMap<ObjectName, (bool, Vec<String>)> = &mut *(hash_set as *mut HashMap<ObjectName, (bool, Vec<String>)>);
set.insert(ObjectName::new_from_variant(key), insert);
}
} }
unsafe fn from_glib_container_variant_set(ptr: *mut glib_sys::GHashTable, from_key: bool) -> HashSet<ObjectName> { unsafe fn from_glib_container_variant_set(ptr: *mut glib_sys::GHashTable) -> HashSet<ObjectName> {
let mut set = HashSet::new(); let mut set = HashSet::new();
let read_variant_table_cb = if from_key { read_variant_table_from_key } else { read_variant_table };
glib_sys::g_hash_table_foreach( glib_sys::g_hash_table_foreach(
ptr, ptr,
Some(read_variant_table_cb), Some(read_variant_table),
&mut set as *mut HashSet<ObjectName> as *mut _, &mut set as *mut HashSet<ObjectName> as *mut _,
); );
glib_sys::g_hash_table_unref(ptr); glib_sys::g_hash_table_unref(ptr);
set set
} }
unsafe fn from_glib_container_variant_map(ptr: *mut glib_sys::GHashTable) -> HashMap<ObjectName, (bool, Vec<String>)> {
let mut set = HashMap::new();
glib_sys::g_hash_table_foreach(
ptr,
Some(read_variant_object_map),
&mut set as *mut HashMap<ObjectName, (bool, Vec<String>)> as *mut _,
);
glib_sys::g_hash_table_unref(ptr);
set
}
/// An open transaction in the repository. /// An open transaction in the repository.
/// ///
/// This will automatically invoke [`ostree::Repo::abort_transaction`] when the value is dropped. /// This will automatically invoke [`ostree::Repo::abort_transaction`] when the value is dropped.
@ -127,7 +140,7 @@ impl Repo {
&mut error, &mut error,
); );
if error.is_null() { if error.is_null() {
Ok(from_glib_container_variant_set(hashtable, false)) Ok(from_glib_container_variant_set(hashtable))
} else { } else {
Err(from_glib_full(error)) Err(from_glib_full(error))
} }
@ -164,7 +177,7 @@ impl Repo {
&self, &self,
flags: OstreeRepoListObjectsFlags, flags: OstreeRepoListObjectsFlags,
cancellable: Option<&P>, cancellable: Option<&P>,
) -> Result<HashSet<ObjectName>, Error> { ) -> Result<HashMap<ObjectName, (bool, Vec<String>)>, 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();
@ -178,7 +191,7 @@ impl Repo {
); );
if error.is_null() { if error.is_null() {
Ok(from_glib_container_variant_set(hashtable, true)) Ok(from_glib_container_variant_map(hashtable))
} else { } else {
Err(from_glib_full(error)) Err(from_glib_full(error))
} }

View File

@ -12,7 +12,7 @@ fn list_repo_objects() {
let mut commit_cnt = 0; let mut commit_cnt = 0;
let objects = repo.repo.list_objects( ffi::OSTREE_REPO_LIST_OBJECTS_ALL, NONE_CANCELLABLE).expect("List Objects"); let objects = repo.repo.list_objects( ffi::OSTREE_REPO_LIST_OBJECTS_ALL, NONE_CANCELLABLE).expect("List Objects");
for object in objects { for (object, _items) in objects {
match object.object_type() { match object.object_type() {
ObjectType::DirTree => { dirtree_cnt += 1; }, ObjectType::DirTree => { dirtree_cnt += 1; },
ObjectType::DirMeta => { dirmeta_cnt += 1; }, ObjectType::DirMeta => { dirmeta_cnt += 1; },