Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ tracing = "0.1.41"
tracing-indicatif = "0.3.9"
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
url = { version = "2.5.4", features = ["serde"] }

[workspace.lints.clippy]
unwrap_in_result = "deny"
unwrap_used = "deny"
panic = "deny"
3 changes: 3 additions & 0 deletions rust/boil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ url.workspace = true

[dev-dependencies]
rstest.workspace = true

[lints]
workspace = true
32 changes: 29 additions & 3 deletions rust/boil/src/build/bakefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ pub enum Error {

#[snafu(display("failed to locate containerfile relative to the {path:?} directory"))]
NoSuchContainerfileExists { path: String },

#[snafu(display("failed to open scoped directory as {path}"))]
OpenScopedDirectory {
source: std::io::Error,
path: String,
},
}

#[derive(Debug, Snafu)]
Expand All @@ -68,6 +74,9 @@ pub enum TargetsError {

#[snafu(display("failed to read image config"))]
ReadImageConfig { source: ImageConfigError },

#[snafu(display("failed to resolve parent directory of image config at {path}", path = path.display()))]
ResolveParentDirectory { path: PathBuf },
}

#[derive(Debug, Default)]
Expand Down Expand Up @@ -111,9 +120,21 @@ impl Targets {
/// Returns a map of all targets by globbing for (nested) image config files.
///
/// The search behaviour can be customized using the provided [`TargetsOptions`].
//
// SAFETY: We purposefully allow the `clippy::unwrap_in_result` lint below in this function.
// We can use expect here, because the glob pattern is defined as a constant and the glob
// function only returns an error if the pattern is invalid. We must ensure the pattern is
// valid at compile time, because there is no need to allow an invalid pattern which would
// render this tool inoperable.
//
// FIXME (@Techassi): This attribute can be used on individual unwrap and expect calls since
// Rust 1.91.0. We should move this attribute to not contaminate an unnecessarily large scope
// once we bump the toolchain to 1.91.0.
// See https://github.com/rust-lang/rust-clippy/pull/15445
#[allow(clippy::unwrap_in_result)]
pub fn all(options: TargetsOptions) -> Result<Self, TargetsError> {
let image_config_paths = glob(ImageConfig::ALL_CONFIGS_GLOB_PATTERN)
.expect("glob pattern must be valid")
.expect("constant glob pattern must be valid")
.filter_map(Result::ok);

let mut targets = Self::default();
Expand All @@ -124,7 +145,9 @@ impl Targets {

let image_name = image_config_path
.parent()
.expect("there must be a parent")
.with_context(|| ResolveParentDirectorySnafu {
path: image_config_path.clone(),
})?
.to_string_lossy()
.into_owned();

Expand Down Expand Up @@ -336,7 +359,10 @@ impl Bakefile {
// By using a cap-std Dir, we can ensure that the paths provided must be relative to
// the appropriate image folder and wont escape it by providing absolute or relative
// paths with traversals (..).
let image_dir = Dir::open_ambient_dir(&image_name, ambient_authority()).unwrap();
let image_dir = Dir::open_ambient_dir(&image_name, ambient_authority())
.with_context(|_| OpenScopedDirectorySnafu {
path: image_name.clone(),
})?;

let dockerfile_path = if let Some(custom_path) = &image_options.dockerfile {
ensure!(
Expand Down
3 changes: 3 additions & 0 deletions rust/patchable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ toml.workspace = true
tracing.workspace = true
tracing-indicatif.workspace = true
tracing-subscriber.workspace = true

[lints]
workspace = true