mirror of
https://github.com/ostreedev/ostree.git
synced 2024-12-22 17:35:55 +03:00
be2075eef0
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)
72 lines
2.0 KiB
Rust
72 lines
2.0 KiB
Rust
use crate::util::TestRepo;
|
|
use gio::NONE_CANCELLABLE;
|
|
use ostree::{checksum_file_from_input, ObjectType};
|
|
|
|
#[test]
|
|
fn list_repo_objects() {
|
|
let repo = TestRepo::new();
|
|
let commit_checksum = repo.test_commit("test");
|
|
let mut dirtree_cnt = 0;
|
|
let mut dirmeta_cnt = 0;
|
|
let mut file_cnt = 0;
|
|
let mut commit_cnt = 0;
|
|
|
|
let objects = repo
|
|
.repo
|
|
.list_objects(ffi::OSTREE_REPO_LIST_OBJECTS_ALL, NONE_CANCELLABLE)
|
|
.expect("List Objects");
|
|
for (object, _items) in objects {
|
|
match object.object_type() {
|
|
ObjectType::DirTree => {
|
|
dirtree_cnt += 1;
|
|
}
|
|
ObjectType::DirMeta => {
|
|
dirmeta_cnt += 1;
|
|
}
|
|
ObjectType::File => {
|
|
file_cnt += 1;
|
|
}
|
|
ObjectType::Commit => {
|
|
assert_eq!(commit_checksum.to_string(), object.checksum());
|
|
commit_cnt += 1;
|
|
}
|
|
x => {
|
|
panic!("unexpected object type {}", x);
|
|
}
|
|
}
|
|
}
|
|
assert_eq!(dirtree_cnt, 2);
|
|
assert_eq!(dirmeta_cnt, 1);
|
|
assert_eq!(file_cnt, 1);
|
|
assert_eq!(commit_cnt, 1);
|
|
}
|
|
|
|
#[test]
|
|
fn should_checksum_file_from_input() {
|
|
let repo = TestRepo::new();
|
|
let commit_checksum = repo.test_commit("test");
|
|
|
|
let objects = repo
|
|
.repo
|
|
.traverse_commit(&commit_checksum, -1, NONE_CANCELLABLE)
|
|
.expect("traverse commit");
|
|
for obj in objects {
|
|
if obj.object_type() != ObjectType::File {
|
|
continue;
|
|
}
|
|
let (stream, file_info, xattrs) = repo
|
|
.repo
|
|
.load_file(obj.checksum(), NONE_CANCELLABLE)
|
|
.expect("load file");
|
|
let result = checksum_file_from_input(
|
|
&file_info,
|
|
Some(&xattrs),
|
|
stream.as_ref(),
|
|
ObjectType::File,
|
|
NONE_CANCELLABLE,
|
|
)
|
|
.expect("checksum file from input");
|
|
assert_eq!(result.to_string(), obj.checksum());
|
|
}
|
|
}
|