Skip to content

Commit

Permalink
Drop cap-std from our public APIs
Browse files Browse the repository at this point in the history
Since it bumped semver (when I didn't expect it to; xref
bytecodealliance/cap-std@963eebf#r121651362

It's not load-bearing enough here to matter versus just passing
an untyped file descriptor.

This mainly means that it will be the `glib` ecosystem which
forces transitive semver bumps for us, not both.
  • Loading branch information
cgwalters committed Aug 31, 2023
1 parent e93ebd7 commit 29df5bf
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

env:
CARGO_TERM_COLOR: always
CARGO_PROJECT_FEATURES: "v2021_5,cap-std-apis"
CARGO_PROJECT_FEATURES: "v2022_6"
# TODO: Automatically query this from the C side
LATEST_LIBOSTREE: "v2022_6"
# Pinned toolchain for linting
Expand Down
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ members = [".", "rust-bindings/sys"]
[dependencies]
base64 = "0.20.0"
bitflags = "1.2.1"
cap-std = { version = "1.0", optional = true}
io-lifetimes = { version = "1.0", optional = true}
ffi = { package = "ostree-sys", path = "rust-bindings/sys", version = "0.13.0" }
gio = "0.16"
glib = "0.16"
Expand All @@ -53,10 +51,10 @@ thiserror = "1.0.20"
[dev-dependencies]
maplit = "1.0.2"
tempfile = "3"
cap-tempfile = "1.0"
io-lifetimes = "1"
cap-tempfile = "2"

[features]
cap-std-apis = ["cap-std", "io-lifetimes", "v2017_10"]
dox = ["ffi/dox"]
v2014_9 = ["ffi/v2014_9"]
v2015_7 = ["v2014_9", "ffi/v2015_7"]
Expand Down
2 changes: 0 additions & 2 deletions rust-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// Re-export our dependencies. See https://gtk-rs.org/blog/2021/06/22/new-release.html
// "Dependencies are re-exported". Users will need e.g. `gio::File`, so this avoids
// them needing to update matching versions.
#[cfg(feature = "cap-std-apis")]
pub use cap_std;
pub use ffi;
pub use gio;
pub use glib;
Expand Down
25 changes: 7 additions & 18 deletions rust-bindings/src/repo.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[cfg(any(feature = "v2016_4", feature = "dox"))]
use crate::RepoListRefsExtFlags;
#[cfg(feature = "cap-std-apis")]
use crate::RepoMode;
use crate::{Checksum, ObjectDetails, ObjectName, ObjectType, Repo, RepoTransactionStats};
use ffi::OstreeRepoListObjectsFlags;
use glib::ffi as glib_sys;
use glib::{self, translate::*, Error, IsA};
use std::os::fd::BorrowedFd;
use std::{
collections::{HashMap, HashSet},
future::Future,
Expand Down Expand Up @@ -105,17 +105,15 @@ impl Repo {
Repo::new(&gio::File::for_path(path.as_ref()))
}

#[cfg(feature = "cap-std-apis")]
/// A version of [`open_at`] which uses cap-std.
pub fn open_at_dir(dir: &cap_std::fs::Dir, path: &str) -> Result<Repo, glib::Error> {
/// Open using the target directory file descriptor.
pub fn open_at_dir(dir: BorrowedFd<'_>, path: &str) -> Result<Repo, glib::Error> {
use std::os::unix::io::AsRawFd;
crate::Repo::open_at(dir.as_raw_fd(), path, gio::Cancellable::NONE)
}

#[cfg(feature = "cap-std-apis")]
/// A version of [`create_at`] which uses cap-std, and also returns the opened repo.
/// A version of [`create_at`] which resolves the path relative to the provided directory file descriptor, and also returns the opened repo.
pub fn create_at_dir(
dir: &cap_std::fs::Dir,
dir: BorrowedFd<'_>,
path: &str,
mode: RepoMode,
options: Option<&glib::Variant>,
Expand Down Expand Up @@ -152,17 +150,8 @@ impl Repo {
}

/// Borrow the directory file descriptor for this repository.
#[cfg(feature = "cap-std-apis")]
pub fn dfd_borrow(&self) -> io_lifetimes::BorrowedFd {
unsafe { io_lifetimes::BorrowedFd::borrow_raw(self.dfd()) }
}

/// Return a new `cap-std` directory reference for this repository.
#[cfg(feature = "cap-std-apis")]
pub fn dfd_as_dir(&self) -> std::io::Result<cap_std::fs::Dir> {
use io_lifetimes::AsFd;
let dfd = self.dfd_borrow();
cap_std::fs::Dir::reopen_dir(&dfd.as_fd())
pub fn dfd_borrow(&self) -> BorrowedFd {
unsafe { BorrowedFd::borrow_raw(self.dfd()) }
}

/// Find all objects reachable from a commit.
Expand Down
8 changes: 5 additions & 3 deletions rust-bindings/tests/repo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::util::*;
use ostree::prelude::*;
use ostree::{ObjectName, ObjectType};
use cap_tempfile::cap_std;
use cap_std::fs::Dir;
use std::os::fd::AsFd;

#[cfg(any(feature = "v2016_8", feature = "dox"))]
mod checkout_at;
Expand Down Expand Up @@ -54,13 +57,12 @@ fn list_commits() {
}

#[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!(Dir::reopen_dir(&test_repo.repo.dfd_borrow()).unwrap().exists("config"));

assert!(test_repo.repo.require_rev("nosuchrev").is_err());

Expand All @@ -69,7 +71,7 @@ fn cap_std_commit() {

assert_eq!(test_repo.repo.require_rev("test").unwrap(), checksum);

let repo2 = ostree::Repo::open_at_dir(&test_repo.dir, ".").unwrap();
let repo2 = ostree::Repo::open_at_dir(test_repo.dir.as_fd(), ".").unwrap();
let refs = repo2
.list_refs(None, gio::Cancellable::NONE)
.expect("failed to list refs");
Expand Down
6 changes: 3 additions & 3 deletions rust-bindings/tests/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use glib::prelude::*;
use glib::GString;
use std::path::Path;
use cap_tempfile::cap_std;
use std::os::fd::AsFd;

#[derive(Debug)]
pub struct TestRepo {
Expand Down Expand Up @@ -28,21 +30,19 @@ 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");
let repo = ostree::Repo::create_at_dir(dir.as_fd(), ".", repo_mode, None).expect("repo create");
Self { dir, repo }
}
}
Expand Down

0 comments on commit 29df5bf

Please sign in to comment.