Add a cap-std-apis feature with open/create

I'm trying to make more use of `cap-std` in our stack, and
this will be a key enabling API.

Actually a notable side benefit of this is that we don't need
to teach the ostree C code itself to use `openat2`, we inherit
cap-std's setup.

All of the internal ostree code using the prior `openat()` should
continue to work.

I only did basic sanity checking of this; there may be bugs
in other APIs.
This commit is contained in:
Colin Walters committed 2022-05-06 12:53:57 -04:00
1 parent 4f7eea6aa7
commit 6940896c4e
5 files changed
+68

No files matched your search

+20
View File
@@ -26,6 +26,26 @@ fn should_commit_content_to_repo_and_list_refs_again() {
assert_eq!(checksum, refs["test"]);
}
#[test]
#[cfg(feature = "cap-std-apis")]
fn cap_std_commit() {
let test_repo = CapTestRepo::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 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();
+20
View File
@@ -28,6 +28,26 @@ impl TestRepo {
}
}
#[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();
let file = gio::File::for_path(