diff --git a/lib/crates/fabro-server/src/run_manifest.rs b/lib/crates/fabro-server/src/run_manifest.rs index 54f8eeeb0..87bd46b31 100644 --- a/lib/crates/fabro-server/src/run_manifest.rs +++ b/lib/crates/fabro-server/src/run_manifest.rs @@ -385,11 +385,8 @@ fn resolve_manifest_dockerfile( return Ok(()); }; let path_owned = path.clone(); - let manifest_path = ManifestPath::from_reference( - config_path.parent().unwrap_or_else(|| Path::new(".")), - &path_owned, - ) - .ok_or_else(|| anyhow!("unsupported dockerfile reference: {path_owned}"))?; + let manifest_path = ManifestPath::from_reference(config_path.parent_or_dot(), &path_owned) + .ok_or_else(|| anyhow!("unsupported dockerfile reference: {path_owned}"))?; let content = files .get(&manifest_path) .cloned() diff --git a/lib/crates/fabro-workflow/src/file_resolver.rs b/lib/crates/fabro-workflow/src/file_resolver.rs index 62bcbb831..6ecdbbf00 100644 --- a/lib/crates/fabro-workflow/src/file_resolver.rs +++ b/lib/crates/fabro-workflow/src/file_resolver.rs @@ -33,9 +33,10 @@ impl BundleFileResolver { impl FileResolver for BundleFileResolver { fn resolve(&self, current_dir: &Path, reference: &str) -> Option { let path = ManifestPath::from_reference(current_dir, reference)?; - self.files.get(&path).map(|content| ResolvedFile { - path: path.as_path().to_path_buf(), - content: content.clone(), + let content = self.files.get(&path)?.clone(); + Some(ResolvedFile { + path: path.into(), + content, }) } } diff --git a/lib/crates/fabro-workflow/src/manifest_path.rs b/lib/crates/fabro-workflow/src/manifest_path.rs index 61108cf0b..44a33808d 100644 --- a/lib/crates/fabro-workflow/src/manifest_path.rs +++ b/lib/crates/fabro-workflow/src/manifest_path.rs @@ -43,6 +43,19 @@ impl ManifestPath { pub fn parent(&self) -> Option<&Path> { self.0.parent() } + + /// Directory that contains this path, falling back to `.` when the path + /// has no parent component (e.g. a bare file name). + #[must_use] + pub fn parent_or_dot(&self) -> &Path { + self.0.parent().unwrap_or_else(|| Path::new(".")) + } +} + +impl From for PathBuf { + fn from(value: ManifestPath) -> Self { + value.0 + } } impl TryFrom for ManifestPath { diff --git a/lib/crates/fabro-workflow/src/workflow_bundle.rs b/lib/crates/fabro-workflow/src/workflow_bundle.rs index bd3624b50..cebd23ba4 100644 --- a/lib/crates/fabro-workflow/src/workflow_bundle.rs +++ b/lib/crates/fabro-workflow/src/workflow_bundle.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::sync::Arc; use serde::{Deserialize, Serialize}; @@ -29,9 +29,7 @@ impl BundledWorkflow { #[must_use] pub fn current_dir(&self) -> PathBuf { - self.path - .parent() - .map_or_else(|| PathBuf::from("."), Path::to_path_buf) + self.path.parent_or_dot().to_path_buf() } } @@ -55,10 +53,7 @@ impl WorkflowBundle { current_workflow_path: &ManifestPath, reference: &str, ) -> Option<&BundledWorkflow> { - let current_dir = current_workflow_path - .parent() - .unwrap_or_else(|| Path::new(".")); - let path = ManifestPath::from_reference(current_dir, reference)?; + let path = ManifestPath::from_reference(current_workflow_path.parent_or_dot(), reference)?; self.workflows.get(&path) }