repo: Metadata return values from `load_file` are not nullable
authorColin Walters <walters@verbum.org>
Thu, 23 Jun 2022 21:36:46 +0000 (17:36 -0400)
committerColin Walters <walters@verbum.org>
Thu, 23 Jun 2022 21:43:42 +0000 (17:43 -0400)
The pattern this API uses in C is to allow the input parameters
pointer targets to be `NULL`, and it doesn't return values in that
case.

A further complexity here is that the API will still return `NULL`
for symbolic links.

But Rust can't express this pattern as is, so we were always
returning values but in `Option<T>` wrappers that the caller needed
to unwrap for the metadata.

(We really want an even more efficient API here that avoids the glib
 objects entirely, e.g. no reason not to pass directly back a type
 that lets Rust directly read from the fd for bare repos, but
 that can come later)

rust-bindings/conf/ostree.toml
rust-bindings/src/auto/repo.rs
rust-bindings/src/auto/versions.txt
rust-bindings/src/repo.rs
rust-bindings/tests/functions/mod.rs

index 64abc10ae5448472fe5029c6978b07170b0128d7..57c2a7931562eed2d11a0c7f67b2fddbc2b613fc 100644 (file)
@@ -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"
index ba34e1dc82538abf314f9136206bfb4cac37d16a..4fd2a29c9039851373a91b28681f9ec034408ada 100644 (file)
@@ -486,18 +486,6 @@ impl Repo {
         }
     }
 
-    #[doc(alias = "ostree_repo_load_file")]
-    pub fn load_file<P: IsA<gio::Cancellable>>(&self, checksum: &str, cancellable: Option<&P>) -> Result<(Option<gio::InputStream>, Option<gio::FileInfo>, Option<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)) }
-        }
-    }
-
     #[doc(alias = "ostree_repo_load_object_stream")]
     pub fn load_object_stream<P: IsA<gio::Cancellable>>(&self, objtype: ObjectType, checksum: &str, cancellable: Option<&P>) -> Result<(gio::InputStream, u64), glib::Error> {
         unsafe {
index 47d437596a243f43e51d964910fceb2950d6e1c8..3c7edf9ef595a0af628b519b0ad9f370370b15b0 100644 (file)
@@ -1,2 +1,2 @@
 Generated by gir (https://github.com/gtk-rs/gir @ e8f82cf6)
-from gir-files (@ 21901c2d)
+from gir-files (@ ee5b3c76)
index 6947f49b7d2bdde5b078531f00807dca3c51b75f..6aeccff55c95b35ed102d9750514dd29e489bf53 100644 (file)
@@ -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.
index 9fa3a91841880949b5a0c2c296af27b6ab10bb74..e041ddfb5c21f270ab04be1e0c3822212cc8e21d 100644 (file)
@@ -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,