Skip to content

Commit

Permalink
Merge pull request #2660 from cgwalters/fix-load-file-api
Browse files Browse the repository at this point in the history
repo: Metadata return values from `load_file` are not nullable
  • Loading branch information
cgwalters authored Jun 24, 2022
2 parents 40703ca + be2075e commit bba9724
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
5 changes: 5 additions & 0 deletions rust-bindings/conf/ostree.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ concurrency = "send"
name = "destination_path"
string_type = "filename"

# Cases where we use nullable output parameters that shouldn't be `Option<T>`
[[object.function]]
pattern = "^(load_file)$"
ignore = true

[[object]]
name = "OSTree.RepoFinder"
status = "generate"
Expand Down
12 changes: 0 additions & 12 deletions rust-bindings/src/auto/repo.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust-bindings/src/auto/versions.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions rust-bindings/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,39 @@ impl Repo {
Ok(self.resolve_rev(refspec, false)?.unwrap())
}

/// Load the contents (for regular files) and metadata for a content object.
#[doc(alias = "ostree_repo_load_file")]
pub fn load_file<P: IsA<gio::Cancellable>>(
&self,
checksum: &str,
cancellable: Option<&P>,
) -> Result<(Option<gio::InputStream>, gio::FileInfo, glib::Variant), glib::Error> {
unsafe {
let mut out_input = ptr::null_mut();
let mut out_file_info = ptr::null_mut();
let mut out_xattrs = ptr::null_mut();
let mut error = ptr::null_mut();
let _ = ffi::ostree_repo_load_file(
self.to_glib_none().0,
checksum.to_glib_none().0,
&mut out_input,
&mut out_file_info,
&mut out_xattrs,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok((
from_glib_full(out_input),
from_glib_full(out_file_info),
from_glib_full(out_xattrs),
))
} else {
Err(from_glib_full(error))
}
}
}

/// Query metadata for a content object.
///
/// This is similar to [`load_file`], but is more efficient if reading the file content is not needed.
Expand Down
4 changes: 2 additions & 2 deletions rust-bindings/tests/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ fn should_checksum_file_from_input() {
.load_file(obj.checksum(), NONE_CANCELLABLE)
.expect("load file");
let result = checksum_file_from_input(
file_info.as_ref().unwrap(),
xattrs.as_ref(),
&file_info,
Some(&xattrs),
stream.as_ref(),
ObjectType::File,
NONE_CANCELLABLE,
Expand Down

0 comments on commit bba9724

Please sign in to comment.