Implement ostree::checksum_file_at
This commit is contained in:
parent
815b8563d5
commit
ad26abaa7e
|
|
@ -1,3 +1,5 @@
|
||||||
|
#[cfg(any(feature = "v2017_13", feature = "dox"))]
|
||||||
|
use crate::ChecksumFlags;
|
||||||
use crate::{Checksum, ObjectType};
|
use crate::{Checksum, ObjectType};
|
||||||
#[cfg(feature = "futures")]
|
#[cfg(feature = "futures")]
|
||||||
use futures::future;
|
use futures::future;
|
||||||
|
|
@ -6,7 +8,7 @@ use glib::translate::*;
|
||||||
use glib_sys::GFALSE;
|
use glib_sys::GFALSE;
|
||||||
#[cfg(feature = "futures")]
|
#[cfg(feature = "futures")]
|
||||||
use std::boxed::Box as Box_;
|
use std::boxed::Box as Box_;
|
||||||
use std::error::Error;
|
use std::error;
|
||||||
use std::mem::MaybeUninit;
|
use std::mem::MaybeUninit;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
|
|
@ -14,7 +16,7 @@ pub fn checksum_file<P: IsA<gio::File>, Q: IsA<gio::Cancellable>>(
|
||||||
f: &P,
|
f: &P,
|
||||||
objtype: ObjectType,
|
objtype: ObjectType,
|
||||||
cancellable: Option<&Q>,
|
cancellable: Option<&Q>,
|
||||||
) -> Result<Checksum, Box<dyn Error>> {
|
) -> Result<Checksum, Box<dyn error::Error>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut out_csum = ptr::null_mut();
|
let mut out_csum = ptr::null_mut();
|
||||||
let mut error = ptr::null_mut();
|
let mut error = ptr::null_mut();
|
||||||
|
|
@ -32,7 +34,7 @@ pub fn checksum_file<P: IsA<gio::File>, Q: IsA<gio::Cancellable>>(
|
||||||
pub fn checksum_file_async<
|
pub fn checksum_file_async<
|
||||||
P: IsA<gio::File>,
|
P: IsA<gio::File>,
|
||||||
Q: IsA<gio::Cancellable>,
|
Q: IsA<gio::Cancellable>,
|
||||||
R: FnOnce(Result<Checksum, Box<dyn Error>>) + Send + 'static,
|
R: FnOnce(Result<Checksum, Box<dyn error::Error>>) + Send + 'static,
|
||||||
>(
|
>(
|
||||||
f: &P,
|
f: &P,
|
||||||
objtype: ObjectType,
|
objtype: ObjectType,
|
||||||
|
|
@ -42,7 +44,7 @@ pub fn checksum_file_async<
|
||||||
) {
|
) {
|
||||||
let user_data: Box<R> = Box::new(callback);
|
let user_data: Box<R> = Box::new(callback);
|
||||||
unsafe extern "C" fn checksum_file_async_trampoline<
|
unsafe extern "C" fn checksum_file_async_trampoline<
|
||||||
R: FnOnce(Result<Checksum, Box<dyn Error>>) + Send + 'static,
|
R: FnOnce(Result<Checksum, Box<dyn error::Error>>) + Send + 'static,
|
||||||
>(
|
>(
|
||||||
_source_object: *mut gobject_sys::GObject,
|
_source_object: *mut gobject_sys::GObject,
|
||||||
res: *mut gio_sys::GAsyncResult,
|
res: *mut gio_sys::GAsyncResult,
|
||||||
|
|
@ -79,7 +81,8 @@ pub fn checksum_file_async_future<P: IsA<gio::File> + Clone + 'static>(
|
||||||
f: &P,
|
f: &P,
|
||||||
objtype: ObjectType,
|
objtype: ObjectType,
|
||||||
io_priority: i32,
|
io_priority: i32,
|
||||||
) -> Box_<dyn future::Future<Output = Result<Checksum, Box<dyn Error>>> + std::marker::Unpin> {
|
) -> Box_<dyn future::Future<Output = Result<Checksum, Box<dyn error::Error>>> + std::marker::Unpin>
|
||||||
|
{
|
||||||
use fragile::Fragile;
|
use fragile::Fragile;
|
||||||
use gio::GioFuture;
|
use gio::GioFuture;
|
||||||
|
|
||||||
|
|
@ -100,7 +103,7 @@ pub fn checksum_file_from_input<P: IsA<gio::InputStream>, Q: IsA<gio::Cancellabl
|
||||||
in_: Option<&P>,
|
in_: Option<&P>,
|
||||||
objtype: ObjectType,
|
objtype: ObjectType,
|
||||||
cancellable: Option<&Q>,
|
cancellable: Option<&Q>,
|
||||||
) -> Result<Checksum, Box<dyn Error>> {
|
) -> Result<Checksum, Box<dyn error::Error>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut out_csum = ptr::null_mut();
|
let mut out_csum = ptr::null_mut();
|
||||||
let mut error = ptr::null_mut();
|
let mut error = ptr::null_mut();
|
||||||
|
|
@ -117,11 +120,43 @@ pub fn checksum_file_from_input<P: IsA<gio::InputStream>, Q: IsA<gio::Cancellabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "v2017_13", feature = "dox"))]
|
||||||
|
pub fn checksum_file_at<P: IsA<gio::Cancellable>>(
|
||||||
|
dfd: i32,
|
||||||
|
path: &std::path::Path,
|
||||||
|
stbuf: Option<&libc::stat>,
|
||||||
|
objtype: ObjectType,
|
||||||
|
flags: ChecksumFlags,
|
||||||
|
cancellable: Option<&P>,
|
||||||
|
) -> Result<glib::GString, glib::Error> {
|
||||||
|
unsafe {
|
||||||
|
let mut out_checksum = ptr::null_mut();
|
||||||
|
let mut error = ptr::null_mut();
|
||||||
|
ostree_sys::ostree_checksum_file_at(
|
||||||
|
dfd,
|
||||||
|
path.to_glib_none().0,
|
||||||
|
stbuf
|
||||||
|
.map(|p| p as *const libc::stat as *mut libc::stat)
|
||||||
|
.unwrap_or(ptr::null_mut()),
|
||||||
|
objtype.to_glib(),
|
||||||
|
flags.to_glib(),
|
||||||
|
&mut out_checksum,
|
||||||
|
cancellable.map(|p| p.as_ref()).to_glib_none().0,
|
||||||
|
&mut error,
|
||||||
|
);
|
||||||
|
if error.is_null() {
|
||||||
|
Ok(from_glib_full(out_checksum))
|
||||||
|
} else {
|
||||||
|
Err(from_glib_full(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe fn checksum_file_error(
|
unsafe fn checksum_file_error(
|
||||||
out_csum: *mut [*mut u8; 32],
|
out_csum: *mut [*mut u8; 32],
|
||||||
error: *mut glib_sys::GError,
|
error: *mut glib_sys::GError,
|
||||||
ret: i32,
|
ret: i32,
|
||||||
) -> Result<Checksum, Box<dyn Error>> {
|
) -> Result<Checksum, Box<dyn error::Error>> {
|
||||||
if !error.is_null() {
|
if !error.is_null() {
|
||||||
Err(Box::<glib::Error>::new(from_glib_full(error)))
|
Err(Box::<glib::Error>::new(from_glib_full(error)))
|
||||||
} else if ret == GFALSE {
|
} else if ret == GFALSE {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
use gio::NONE_CANCELLABLE;
|
||||||
|
use ostree::{checksum_file_at, ChecksumFlags, ObjectType, RepoMode};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use util::TestRepo;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_checksum_file_at() {
|
||||||
|
let repo = TestRepo::new_with_mode(RepoMode::BareUser);
|
||||||
|
repo.test_commit("test");
|
||||||
|
|
||||||
|
let result = checksum_file_at(
|
||||||
|
repo.repo.get_dfd(),
|
||||||
|
&PathBuf::from(
|
||||||
|
"objects/89/f84ca9854a80e85b583e46a115ba4985254437027bad34f0b113219323d3f8.file",
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
ObjectType::File,
|
||||||
|
ChecksumFlags::IGNORE_XATTRS,
|
||||||
|
NONE_CANCELLABLE,
|
||||||
|
)
|
||||||
|
.expect("checksum file at");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
result.as_str(),
|
||||||
|
"89f84ca9854a80e85b583e46a115ba4985254437027bad34f0b113219323d3f8",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
use gio::NONE_CANCELLABLE;
|
use gio::NONE_CANCELLABLE;
|
||||||
use glib::Cast;
|
use glib::prelude::*;
|
||||||
use ostree::{checksum_file, checksum_file_from_input, ObjectType, RepoFile, RepoFileExt};
|
use ostree::prelude::*;
|
||||||
|
use ostree::{checksum_file, checksum_file_from_input, ObjectType, RepoFile};
|
||||||
use util::TestRepo;
|
use util::TestRepo;
|
||||||
|
|
||||||
|
#[cfg(feature = "v2017_13")]
|
||||||
|
mod checksum_file_at;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_checksum_file() {
|
fn should_checksum_file() {
|
||||||
let repo = TestRepo::new();
|
let repo = TestRepo::new();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue