8000 feat(sessions): Add composability/resolution to loadouts by evanspearman · Pull Request #348 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
8000
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ lzma-rs = "0.3"
nickel-lang-core = { version = "0.18", default-features = false, features = ["format"] }

nix = { version = "0.31", features = ["fs"] }
nutype = { version = "0.6", features = ["serde"] }
object = { version = "0.39", default-features = false, features = ["archive", "elf", "read_core", "std"] }
oci-spec = "0.10"
path-absolutize = "3.1"
Expand Down Expand Up @@ -101,6 +102,7 @@ tonic-prost = "0.14.6"
tonic-prost-build = "0.14.6"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }
thiserror = "2"
url = "2" # keep in sync with reqwest
uuid = { version = "1.23", features = ["v4", "v7", "serde"] }
zstd = "0.13"
Expand Down
1 change: 1 addition & 0 deletions crates/paths/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ publish.workspace = true
[dependencies]
camino.workspace = true
serde.workspace = true
thiserror.workspace = true

[dev-dependencies]
toml.workspace = true
Expand Down
91 changes: 52 additions & 39 deletions crates/paths/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,16 @@ pub type ConfigRelPath = RelPath<ConfigRelative>;

/// Errors produced when constructing a path.
#[non_exhaustive]
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, thiserror::Error)]
pub enum Error {
/// An [`AbsPath`] was constructed from a non-absolute input.
#[error("expected an absolute path, got: {0}")]
NotAbsolute(Utf8PathBuf),
/// A [`RelPath`] was constructed from an absolute input.
#[error("expected a relative path, got: {0}")]
IsAbsolute(Utf8PathBuf),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NotAbsolute(p) => write!(f, "expected an absolute path, got: {p}"),
Self::IsAbsolute(p) => write!(f, "expected a relative path, got: {p}"),
}
}
}

impl std::error::Error for Error {}

#[doc(hidden)]
pub const fn _validate_subdir(s: &str) {
let bytes = s.as_bytes();
Expand Down Expand Up @@ -199,6 +190,34 @@ impl<R: Realm> AbsPath<R> {
}
}

/// Construct an [`AbsPath`] without verifying that `p` is
/// absolute.
///
/// Use only when the caller has already proven absoluteness by
/// other means (e.g. the path came from `walkdir::WalkDir::new`
/// rooted at an absolute path). A `debug_assert!` catches misuse
/// in development builds; release builds skip the check.
pub fn new_unchecked(p: impl Into<Utf8PathBuf>) -> Self {
let p = p.into();
debug_assert!(p.is_absolute());
Self {
inner: p,
_realm: PhantomData,
}
}
Comment thread
evanspearman marked this conversation as resolved.
Resolved

/// Returns the root path (`/`), assuming a POSIX-like system.
///
/// This is a convenience for places that need a known-absolute
/// root in the [`Realm`] of the caller. Not appropriate on
/// Windows, where the root concept differs.
pub fn root() -> Self {
Self {
inner: Utf8PathBuf::from("/"),
_realm: PhantomData,
}
}

/// Borrows the underlying UTF-8 path.
#[must_use]
pub fn as_utf8_path(&self) -> &Utf8Path {
Expand Down Expand Up @@ -415,6 +434,22 @@ impl<R: Realm> RelPath<R> {
}
}

/// Construct a [`RelPath`] without verifying that `p` is
/// relative.
///
/// Use only when the caller has already proven relativity by other
/// means (e.g. the path was produced by `strip_prefix` against a
/// known absolute root). A `debug_assert!` catches misuse in
/// development builds; release builds skip the check.
pub fn new_unchecked(p: impl Into<Utf8PathBuf>) -> Self {
let p = p.into();
debug_assert!(p.is_relative());
Self {
inner: p,
_realm: PhantomData,
}
}

/// Borrows the underlying UTF-8 path.
#[must_use]
pub fn as_utf8_path(&self) -> &Utf8Path {
Expand Down Expand Up @@ -842,41 +877,19 @@ impl CwdResolvable for Daemon {}
/// Errors produced when resolving a [`CwdRelative`] against the
/// process current working directory.
#[non_exhaustive]
#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum CwdResolveError {
/// `std::env::current_dir` failed.
Cwd(std::io::Error),
#[error("failed to read the current working directory")]
Cwd(#[source] std::io::Error),
/// The cwd is not valid UTF-8.
#[error("current working directory `{}` is not valid UTF-8", .0.display())]
NonUtf8Cwd(std::path::PathBuf),
/// The cwd is somehow not absolute (an OS-level invariant violation).
#[error("current working directory `{0}` is not absolute")]
CwdNotAbsolute(Utf8PathBuf),
}

impl fmt::Display for CwdResolveError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Cwd(_) => f.write_str("failed to read the current working directory"),
Self::NonUtf8Cwd(p) => write!(
f,
"current working directory `{}` is not valid UTF-8",
p.display(),
),
Self::CwdNotAbsolute(p) => {
write!(f, "current working directory `{p}` is not absolute")
}
}
}
}

impl std::error::Error for CwdResolveError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Cwd(e) => Some(e),
_ => None,
}
}
}

/// A CLI-supplied path: absolute is taken as-is, relative is captured
/// for later resolution against the process current working directory.
///
Expand Down
3 changes: 3 additions & 0 deletions crates/sessions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ publish.workspace = true
common.workspace = true
globset.workspace = true
camino.workspace = true
nutype.workspace = true
paths.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
uuid.workspace = true
walkdir.workspace = true

[dev-dependencies]
tempfile.workspace = true
Expand Down
Loading
Loading
0