ostree/cargo: bump to ostree-sys 0.9.2
This commit is contained in:
1 parent
61b4629b37
commit
3fc55a524b
91 files changed
+2
-1
No files matched your search
@@ -0,0 +1,13 @@
|
||||
use crate::util::*;
|
||||
use std::error::Error;
|
||||
|
||||
#[test]
|
||||
fn variant_types() -> Result<(), Box<dyn Error>> {
|
||||
let tr = TestRepo::new();
|
||||
let commit_checksum = tr.test_commit("test");
|
||||
let repo = &tr.repo;
|
||||
let commit_v = repo.load_variant(ostree::ObjectType::Commit, commit_checksum.as_str())?;
|
||||
let commit = commit_v.get::<ostree::CommitVariantType>().unwrap();
|
||||
assert_eq!(commit.3, "Test Commit");
|
||||
Ok(())
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,71 @@
|
||||
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.as_ref().unwrap(),
|
||||
xattrs.as_ref(),
|
||||
stream.as_ref(),
|
||||
ObjectType::File,
|
||||
NONE_CANCELLABLE,
|
||||
)
|
||||
.expect("checksum file from input");
|
||||
assert_eq!(result.to_string(), obj.checksum());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
use crate::util::*;
|
||||
use gio::NONE_CANCELLABLE;
|
||||
use ostree::*;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
#[test]
|
||||
fn should_checkout_at_with_none_options() {
|
||||
let test_repo = TestRepo::new();
|
||||
let checksum = test_repo.test_commit("test");
|
||||
let checkout_dir = tempfile::tempdir().expect("checkout dir");
|
||||
|
||||
let dirfd = openat::Dir::open(checkout_dir.path()).expect("openat");
|
||||
test_repo
|
||||
.repo
|
||||
.checkout_at(
|
||||
None,
|
||||
dirfd.as_raw_fd(),
|
||||
"test-checkout",
|
||||
&checksum,
|
||||
NONE_CANCELLABLE,
|
||||
)
|
||||
.expect("checkout at");
|
||||
|
||||
assert_test_file(checkout_dir.path());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_checkout_at_with_default_options() {
|
||||
let test_repo = TestRepo::new();
|
||||
let checksum = test_repo.test_commit("test");
|
||||
let checkout_dir = tempfile::tempdir().expect("checkout dir");
|
||||
|
||||
let dirfd = openat::Dir::open(checkout_dir.path()).expect("openat");
|
||||
test_repo
|
||||
.repo
|
||||
.checkout_at(
|
||||
Some(&RepoCheckoutAtOptions::default()),
|
||||
dirfd.as_raw_fd(),
|
||||
"test-checkout",
|
||||
&checksum,
|
||||
NONE_CANCELLABLE,
|
||||
)
|
||||
.expect("checkout at");
|
||||
|
||||
assert_test_file(checkout_dir.path());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_checkout_at_with_options() {
|
||||
let test_repo = TestRepo::new();
|
||||
let checksum = test_repo.test_commit("test");
|
||||
let checkout_dir = tempfile::tempdir().expect("checkout dir");
|
||||
|
||||
let dirfd = openat::Dir::open(checkout_dir.path()).expect("openat");
|
||||
test_repo
|
||||
.repo
|
||||
.checkout_at(
|
||||
Some(&RepoCheckoutAtOptions {
|
||||
mode: RepoCheckoutMode::User,
|
||||
overwrite_mode: RepoCheckoutOverwriteMode::AddFiles,
|
||||
enable_fsync: true,
|
||||
devino_to_csum_cache: Some(RepoDevInoCache::new()),
|
||||
..Default::default()
|
||||
}),
|
||||
dirfd.as_raw_fd(),
|
||||
"test-checkout",
|
||||
&checksum,
|
||||
NONE_CANCELLABLE,
|
||||
)
|
||||
.expect("checkout at");
|
||||
|
||||
assert_test_file(checkout_dir.path());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "v2018_2")]
|
||||
fn should_checkout_at_with_filter() {
|
||||
use std::path::Path;
|
||||
|
||||
let test_repo = TestRepo::new();
|
||||
let checksum = test_repo.test_commit("test");
|
||||
let checkout_dir = tempfile::tempdir().expect("checkout dir");
|
||||
|
||||
let dirfd = openat::Dir::open(checkout_dir.path()).expect("openat");
|
||||
test_repo
|
||||
.repo
|
||||
.checkout_at(
|
||||
Some(&RepoCheckoutAtOptions {
|
||||
filter: RepoCheckoutFilter::new(|_repo, path, _stat| {
|
||||
if path == Path::new("/testdir/testfile") {
|
||||
RepoCheckoutFilterResult::Skip
|
||||
} else {
|
||||
RepoCheckoutFilterResult::Allow
|
||||
}
|
||||
}),
|
||||
..Default::default()
|
||||
}),
|
||||
dirfd.as_raw_fd(),
|
||||
"test-checkout",
|
||||
&checksum,
|
||||
NONE_CANCELLABLE,
|
||||
)
|
||||
.expect("checkout at");
|
||||
|
||||
let testdir = checkout_dir.path().join("test-checkout").join("testdir");
|
||||
assert!(std::fs::read_dir(&testdir).is_ok());
|
||||
assert!(std::fs::File::open(&testdir.join("testfile")).is_err());
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
use crate::util::*;
|
||||
use ostree::gio::NONE_CANCELLABLE;
|
||||
use ostree::prelude::*;
|
||||
use ostree::{ObjectName, ObjectType};
|
||||
|
||||
#[cfg(feature = "v2016_8")]
|
||||
mod checkout_at;
|
||||
|
||||
#[test]
|
||||
fn should_commit_content_to_repo_and_list_refs_again() {
|
||||
let test_repo = TestRepo::new();
|
||||
|
||||
assert!(test_repo.repo.require_rev("nosuchrev").is_err());
|
||||
|
||||
let mtree = create_mtree(&test_repo.repo);
|
||||
let checksum = commit(&test_repo.repo, &mtree, "test");
|
||||
|
||||
assert_eq!(test_repo.repo.require_rev("test").unwrap(), checksum);
|
||||
|
||||
let repo = ostree::Repo::new_for_path(test_repo.dir.path());
|
||||
repo.open(NONE_CANCELLABLE).expect("OSTree test_repo");
|
||||
let refs = repo
|
||||
.list_refs(None, NONE_CANCELLABLE)
|
||||
.expect("failed to list refs");
|
||||
assert_eq!(1, refs.len());
|
||||
assert_eq!(checksum, refs["test"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "cap-std-apis")]
|
||||
fn cap_std_commit() {
|
||||
let test_repo = CapTestRepo::new();
|
||||
|
||||
assert!(test_repo.dir.exists("config"));
|
||||
// Also test re-acquiring a new dfd
|
||||
assert!(test_repo.repo.dfd_as_dir().unwrap().exists("config"));
|
||||
|
||||
assert!(test_repo.repo.require_rev("nosuchrev").is_err());
|
||||
|
||||
let mtree = create_mtree(&test_repo.repo);
|
||||
let checksum = commit(&test_repo.repo, &mtree, "test");
|
||||
|
||||
assert_eq!(test_repo.repo.require_rev("test").unwrap(), checksum);
|
||||
|
||||
let repo2 = ostree::Repo::open_at_dir(&test_repo.dir, ".").unwrap();
|
||||
let refs = repo2
|
||||
.list_refs(None, NONE_CANCELLABLE)
|
||||
.expect("failed to list refs");
|
||||
assert_eq!(1, refs.len());
|
||||
assert_eq!(checksum, refs["test"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repo_traverse_and_read() {
|
||||
let test_repo = TestRepo::new();
|
||||
let checksum = test_repo.test_commit("test");
|
||||
|
||||
let objects = test_repo
|
||||
.repo
|
||||
.traverse_commit(&checksum, -1, NONE_CANCELLABLE)
|
||||
.expect("traverse commit");
|
||||
|
||||
assert_eq!(
|
||||
maplit::hashset!(
|
||||
ObjectName::new(
|
||||
"89f84ca9854a80e85b583e46a115ba4985254437027bad34f0b113219323d3f8",
|
||||
ObjectType::File
|
||||
),
|
||||
ObjectName::new(
|
||||
"5280a884f930cae329e2e39d52f2c8e910c2ef4733216b67679db32a2b56c4db",
|
||||
ObjectType::DirTree
|
||||
),
|
||||
ObjectName::new(
|
||||
"c81acde323d73f8639fc84f1ded17bbafc415e645f845e9f3b16a4906857c2d4",
|
||||
ObjectType::DirTree
|
||||
),
|
||||
ObjectName::new(
|
||||
"ad49a0f4e3bc165361b6d17e8a865d479b373ee67d89ac6f0ce871f27da1be6d",
|
||||
ObjectType::DirMeta
|
||||
),
|
||||
ObjectName::new(checksum, ObjectType::Commit)
|
||||
),
|
||||
objects
|
||||
);
|
||||
|
||||
let dirmeta = test_repo
|
||||
.repo
|
||||
.read_dirmeta("ad49a0f4e3bc165361b6d17e8a865d479b373ee67d89ac6f0ce871f27da1be6d")
|
||||
.unwrap();
|
||||
// Right now, the uid/gid are actually that of the test runner
|
||||
assert_eq!(dirmeta.mode, 0o40750);
|
||||
|
||||
let (finfo, _xattrs) = test_repo
|
||||
.repo
|
||||
.query_file(
|
||||
"89f84ca9854a80e85b583e46a115ba4985254437027bad34f0b113219323d3f8",
|
||||
NONE_CANCELLABLE,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(finfo.size(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_checkout_tree() {
|
||||
let test_repo = TestRepo::new();
|
||||
let _ = test_repo.test_commit("test");
|
||||
|
||||
let checkout_dir = tempfile::tempdir().expect("checkout dir");
|
||||
let file = test_repo
|
||||
.repo
|
||||
.read_commit("test", NONE_CANCELLABLE)
|
||||
.expect("read commit")
|
||||
.0
|
||||
.downcast::<ostree::RepoFile>()
|
||||
.expect("RepoFile");
|
||||
let info = file
|
||||
.query_info("*", gio::FileQueryInfoFlags::NONE, NONE_CANCELLABLE)
|
||||
.expect("file info");
|
||||
test_repo
|
||||
.repo
|
||||
.checkout_tree(
|
||||
ostree::RepoCheckoutMode::User,
|
||||
ostree::RepoCheckoutOverwriteMode::None,
|
||||
&gio::File::for_path(checkout_dir.path().join("test-checkout")),
|
||||
&file,
|
||||
&info,
|
||||
NONE_CANCELLABLE,
|
||||
)
|
||||
.expect("checkout tree");
|
||||
|
||||
assert_test_file(checkout_dir.path());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_write_content_to_repo() {
|
||||
let src = TestRepo::new();
|
||||
let mtree = create_mtree(&src.repo);
|
||||
let checksum = commit(&src.repo, &mtree, "test");
|
||||
|
||||
let dest = TestRepo::new();
|
||||
let objects = src
|
||||
.repo
|
||||
.traverse_commit(&checksum, -1, NONE_CANCELLABLE)
|
||||
.expect("traverse");
|
||||
for obj in objects {
|
||||
match obj.object_type() {
|
||||
ObjectType::File => copy_file(&src, &dest, &obj),
|
||||
_ => copy_metadata(&src, &dest, &obj),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "v2016_4")]
|
||||
fn repo_file() {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
let test_repo = TestRepo::new();
|
||||
let m1 = test_repo.repo.dfd_as_file().unwrap().metadata().unwrap();
|
||||
let m2 = test_repo.repo.dfd_as_file().unwrap().metadata().unwrap();
|
||||
assert_eq!(m1.dev(), m2.dev());
|
||||
assert_eq!(m1.ino(), m2.ino());
|
||||
}
|
||||
|
||||
fn copy_file(src: &TestRepo, dest: &TestRepo, obj: &ObjectName) {
|
||||
let (stream, len) = src
|
||||
.repo
|
||||
.load_object_stream(obj.object_type(), obj.checksum(), NONE_CANCELLABLE)
|
||||
.expect("load object stream");
|
||||
let out_csum = dest
|
||||
.repo
|
||||
.write_content(None, &stream, len, NONE_CANCELLABLE)
|
||||
.expect("write content");
|
||||
assert_eq!(out_csum.to_string(), obj.checksum());
|
||||
}
|
||||
|
||||
fn copy_metadata(src: &TestRepo, dest: &TestRepo, obj: &ObjectName) {
|
||||
let data = src
|
||||
.repo
|
||||
.load_variant(obj.object_type(), obj.checksum())
|
||||
.expect("load variant");
|
||||
let out_csum = dest
|
||||
.repo
|
||||
.write_metadata(obj.object_type(), None, &data, NONE_CANCELLABLE)
|
||||
.expect("write metadata");
|
||||
assert_eq!(out_csum.to_string(), obj.checksum());
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
use ostree::prelude::*;
|
||||
use ostree::{gio, glib};
|
||||
|
||||
#[test]
|
||||
fn sign_api_should_work() {
|
||||
let dummy_sign = ostree::Sign::by_name("dummy").unwrap();
|
||||
assert_eq!(dummy_sign.name().unwrap(), "dummy");
|
||||
|
||||
let result = ostree::prelude::SignExt::data(
|
||||
&dummy_sign,
|
||||
&glib::Bytes::from_static(b"1234"),
|
||||
gio::NONE_CANCELLABLE,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
|
||||
let result = dummy_sign.data_verify(&glib::Bytes::from_static(b"1234"), &"1234".to_variant());
|
||||
assert!(result.is_err());
|
||||
|
||||
let result = ostree::Sign::by_name("NOPE");
|
||||
assert!(result.is_err());
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
mod core;
|
||||
mod functions;
|
||||
mod repo;
|
||||
#[cfg(feature = "v2020_2")]
|
||||
mod sign;
|
||||
mod util;
|
||||
@@ -0,0 +1,97 @@
|
||||
use gio::NONE_CANCELLABLE;
|
||||
use glib::prelude::*;
|
||||
use glib::GString;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TestRepo {
|
||||
pub dir: tempfile::TempDir,
|
||||
pub repo: ostree::Repo,
|
||||
}
|
||||
|
||||
impl TestRepo {
|
||||
pub fn new() -> TestRepo {
|
||||
TestRepo::new_with_mode(ostree::RepoMode::Archive)
|
||||
}
|
||||
|
||||
pub fn new_with_mode(repo_mode: ostree::RepoMode) -> TestRepo {
|
||||
let dir = tempfile::tempdir().expect("temp repo dir");
|
||||
let repo = ostree::Repo::new_for_path(dir.path());
|
||||
repo.create(repo_mode, NONE_CANCELLABLE)
|
||||
.expect("OSTree repo");
|
||||
TestRepo { dir, repo }
|
||||
}
|
||||
|
||||
pub fn test_commit(&self, ref_: &str) -> GString {
|
||||
let mtree = create_mtree(&self.repo);
|
||||
commit(&self.repo, &mtree, ref_)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg(feature = "cap-std-apis")]
|
||||
pub struct CapTestRepo {
|
||||
pub dir: cap_tempfile::TempDir,
|
||||
pub repo: ostree::Repo,
|
||||
}
|
||||
|
||||
#[cfg(feature = "cap-std-apis")]
|
||||
impl CapTestRepo {
|
||||
pub fn new() -> Self {
|
||||
Self::new_with_mode(ostree::RepoMode::Archive)
|
||||
}
|
||||
|
||||
pub fn new_with_mode(repo_mode: ostree::RepoMode) -> Self {
|
||||
let dir = cap_tempfile::tempdir(cap_std::ambient_authority()).unwrap();
|
||||
let repo = ostree::Repo::create_at_dir(&dir, ".", repo_mode, None).expect("repo create");
|
||||
Self { dir, repo }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_mtree(repo: &ostree::Repo) -> ostree::MutableTree {
|
||||
let mtree = ostree::MutableTree::new();
|
||||
assert_eq!(mtree.copy_files().len(), 0);
|
||||
assert_eq!(mtree.copy_subdirs().len(), 0);
|
||||
let file = gio::File::for_path(
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("tests")
|
||||
.join("data")
|
||||
.join("test.tar"),
|
||||
);
|
||||
repo.write_archive_to_mtree(&file, &mtree, None, true, NONE_CANCELLABLE)
|
||||
.expect("test mtree");
|
||||
mtree
|
||||
}
|
||||
|
||||
pub fn commit(repo: &ostree::Repo, mtree: &ostree::MutableTree, ref_: &str) -> GString {
|
||||
let txn = repo
|
||||
.auto_transaction(NONE_CANCELLABLE)
|
||||
.expect("prepare transaction");
|
||||
let repo_file = repo
|
||||
.write_mtree(mtree, NONE_CANCELLABLE)
|
||||
.expect("write mtree")
|
||||
.downcast::<ostree::RepoFile>()
|
||||
.unwrap();
|
||||
let checksum = repo
|
||||
.write_commit(
|
||||
None,
|
||||
"Test Commit".into(),
|
||||
None,
|
||||
None,
|
||||
&repo_file,
|
||||
NONE_CANCELLABLE,
|
||||
)
|
||||
.expect("write commit");
|
||||
repo.transaction_set_ref(None, ref_, checksum.as_str().into());
|
||||
txn.commit(NONE_CANCELLABLE).expect("commit transaction");
|
||||
checksum
|
||||
}
|
||||
|
||||
pub fn assert_test_file(checkout: &Path) {
|
||||
let testfile_path = checkout
|
||||
.join("test-checkout")
|
||||
.join("testdir")
|
||||
.join("testfile");
|
||||
let testfile_contents = std::fs::read_to_string(testfile_path).expect("test file");
|
||||
assert_eq!("test\n", testfile_contents);
|
||||
}
|
||||
Reference in new issue
Block a user