ostree_ext/
ostree_manual.rs

1//! Manual workarounds for ostree bugs
2
3use std::io::Read;
4use std::ptr;
5
6use ostree::prelude::{Cast, InputStreamExtManual};
7use ostree::{gio, glib};
8
9/// Equivalent of `g_file_read()` for ostree::RepoFile to work around https://github.com/ostreedev/ostree/issues/2703
10#[allow(unsafe_code)]
11pub fn repo_file_read(f: &ostree::RepoFile) -> Result<gio::InputStream, glib::Error> {
12    use glib::translate::*;
13    let stream = unsafe {
14        let f = f.upcast_ref::<gio::File>();
15        let mut error = ptr::null_mut();
16        let stream = gio::ffi::g_file_read(f.to_glib_none().0, ptr::null_mut(), &mut error);
17        if !error.is_null() {
18            return Err(from_glib_full(error));
19        }
20        // Upcast to GInputStream here
21        from_glib_full(stream as *mut gio::ffi::GInputStream)
22    };
23
24    Ok(stream)
25}
26
27/// Read a repo file to a string.
28pub fn repo_file_read_to_string(f: &ostree::RepoFile) -> anyhow::Result<String> {
29    let mut r = String::new();
30    let mut s = repo_file_read(f)?.into_read();
31    s.read_to_string(&mut r)?;
32    Ok(r)
33}