mirror of
https://github.com/ostreedev/ostree.git
synced 2025-08-25 13:49:24 +03:00
Implement ostree::checksum_file
This commit is contained in:
committed by
Colin Walters
parent
4cd981d01b
commit
7f3bd56d0d
34
rust-bindings/rust/src/functions.rs
Normal file
34
rust-bindings/rust/src/functions.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use crate::{Checksum, ObjectType};
|
||||
use glib::prelude::*;
|
||||
use glib::translate::*;
|
||||
use glib_sys::GFALSE;
|
||||
use std::error::Error;
|
||||
use std::ptr;
|
||||
|
||||
pub fn checksum_file<P: IsA<gio::File>, Q: IsA<gio::Cancellable>>(
|
||||
f: &P,
|
||||
objtype: ObjectType,
|
||||
cancellable: Option<&Q>,
|
||||
) -> Result<Checksum, Box<dyn Error>> {
|
||||
unsafe {
|
||||
let mut out_csum = ptr::null_mut();
|
||||
let mut error = ptr::null_mut();
|
||||
let ret = ostree_sys::ostree_checksum_file(
|
||||
f.as_ref().to_glib_none().0,
|
||||
objtype.to_glib(),
|
||||
&mut out_csum,
|
||||
cancellable.map(|p| p.as_ref()).to_glib_none().0,
|
||||
&mut error,
|
||||
);
|
||||
|
||||
if !error.is_null() {
|
||||
Err(Box::<glib::Error>::new(from_glib_full(error)))
|
||||
} else if ret == GFALSE {
|
||||
Err(Box::new(glib_bool_error!(
|
||||
"unknown error in ostree_checksum_file"
|
||||
)))
|
||||
} else {
|
||||
Ok(Checksum::from_glib_full(out_csum))
|
||||
}
|
||||
}
|
||||
}
|
@ -37,6 +37,7 @@ pub use crate::auto::*;
|
||||
mod checksum;
|
||||
#[cfg(any(feature = "v2018_6", feature = "dox"))]
|
||||
mod collection_ref;
|
||||
mod functions;
|
||||
#[cfg(any(feature = "v2019_3", feature = "dox"))]
|
||||
mod kernel_args;
|
||||
mod object_name;
|
||||
@ -47,6 +48,7 @@ mod se_policy;
|
||||
pub use crate::checksum::*;
|
||||
#[cfg(any(feature = "v2018_6", feature = "dox"))]
|
||||
pub use crate::collection_ref::*;
|
||||
pub use crate::functions::*;
|
||||
#[cfg(any(feature = "v2019_3", feature = "dox"))]
|
||||
pub use crate::kernel_args::*;
|
||||
pub use crate::object_name::*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use functions::{object_name_deserialize, object_name_serialize, object_to_string};
|
||||
use crate::{object_name_deserialize, object_name_serialize, object_to_string};
|
||||
use glib;
|
||||
use glib::translate::*;
|
||||
use glib::GString;
|
||||
|
@ -11,6 +11,7 @@ use glib::Error;
|
||||
use glib::IsA;
|
||||
use glib_sys;
|
||||
use ostree_sys;
|
||||
#[cfg(feature = "futures")]
|
||||
use std::boxed::Box as Box_;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::Path;
|
||||
|
21
rust-bindings/rust/tests/functions/mod.rs
Normal file
21
rust-bindings/rust/tests/functions/mod.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use gio::NONE_CANCELLABLE;
|
||||
use glib::Cast;
|
||||
use ostree::{checksum_file, ObjectType, RepoFile, RepoFileExt};
|
||||
use util::TestRepo;
|
||||
|
||||
#[test]
|
||||
fn should_checksum_file() {
|
||||
let repo = TestRepo::new();
|
||||
repo.test_commit("test");
|
||||
|
||||
let file = repo
|
||||
.repo
|
||||
.read_commit("test", NONE_CANCELLABLE)
|
||||
.expect("read commit")
|
||||
.0
|
||||
.downcast::<RepoFile>()
|
||||
.expect("downcast");
|
||||
let result = checksum_file(&file, ObjectType::File, NONE_CANCELLABLE).expect("checksum file");
|
||||
|
||||
assert_eq!(file.get_checksum().unwrap(), result.to_string());
|
||||
}
|
@ -6,5 +6,6 @@ extern crate tempfile;
|
||||
#[macro_use]
|
||||
extern crate maplit;
|
||||
|
||||
mod functions;
|
||||
mod repo;
|
||||
mod util;
|
||||
|
Reference in New Issue
Block a user