Fix some issues with RepoFile

This commit is contained in:
Felix Krull authored and Colin Walters committed 2022-05-06 12:53:53 -04:00
1 parent 26b5729c53
commit 0bf8f3f52e
3 files changed
+63 -19

No files matched your search

+37
View File
@@ -34,6 +34,10 @@ pub trait RepoFileExt {
fn get_root(&self) -> Option<RepoFile>;
fn get_xattrs<'a, P: Into<Option<&'a gio::Cancellable>>>(&self, cancellable: P) -> Result<glib::Variant, Error>;
fn tree_find_child(&self, name: &str) -> (i32, bool, glib::Variant);
fn tree_get_contents(&self) -> Option<glib::Variant>;
fn tree_get_contents_checksum(&self) -> Option<String>;
@@ -42,6 +46,8 @@ pub trait RepoFileExt {
fn tree_get_metadata_checksum(&self) -> Option<String>;
fn tree_query_child<'a, P: Into<Option<&'a gio::Cancellable>>>(&self, n: i32, attributes: &str, flags: gio::FileQueryInfoFlags, cancellable: P) -> Result<gio::FileInfo, Error>;
fn tree_set_metadata(&self, checksum: &str, metadata: &glib::Variant);
}
@@ -72,6 +78,26 @@ impl<O: IsA<RepoFile>> RepoFileExt for O {
}
}
fn get_xattrs<'a, P: Into<Option<&'a gio::Cancellable>>>(&self, cancellable: P) -> Result<glib::Variant, Error> {
let cancellable = cancellable.into();
let cancellable = cancellable.to_glib_none();
unsafe {
let mut out_xattrs = ptr::null_mut();
let mut error = ptr::null_mut();
let _ = ffi::ostree_repo_file_get_xattrs(self.to_glib_none().0, &mut out_xattrs, cancellable.0, &mut error);
if error.is_null() { Ok(from_glib_full(out_xattrs)) } else { Err(from_glib_full(error)) }
}
}
fn tree_find_child(&self, name: &str) -> (i32, bool, glib::Variant) {
unsafe {
let mut is_dir = mem::uninitialized();
let mut out_container = ptr::null_mut();
let ret = ffi::ostree_repo_file_tree_find_child(self.to_glib_none().0, name.to_glib_none().0, &mut is_dir, &mut out_container);
(ret, from_glib(is_dir), from_glib_full(out_container))
}
}
fn tree_get_contents(&self) -> Option<glib::Variant> {
unsafe {
from_glib_full(ffi::ostree_repo_file_tree_get_contents(self.to_glib_none().0))
@@ -96,6 +122,17 @@ impl<O: IsA<RepoFile>> RepoFileExt for O {
}
}
fn tree_query_child<'a, P: Into<Option<&'a gio::Cancellable>>>(&self, n: i32, attributes: &str, flags: gio::FileQueryInfoFlags, cancellable: P) -> Result<gio::FileInfo, Error> {
let cancellable = cancellable.into();
let cancellable = cancellable.to_glib_none();
unsafe {
let mut out_info = ptr::null_mut();
let mut error = ptr::null_mut();
let _ = ffi::ostree_repo_file_tree_query_child(self.to_glib_none().0, n, attributes.to_glib_none().0, flags.to_glib(), &mut out_info, cancellable.0, &mut error);
if error.is_null() { Ok(from_glib_full(out_info)) } else { Err(from_glib_full(error)) }
}
}
fn tree_set_metadata(&self, checksum: &str, metadata: &glib::Variant) {
unsafe {
ffi::ostree_repo_file_tree_set_metadata(self.to_glib_none().0, checksum.to_glib_none().0, metadata.to_glib_none().0);