| 365 | |
| 366 | impl ProjectPath { |
| 367 | pub fn resolve(project_root: &Path, path: &Path) -> Result<Self> { |
| 368 | validate_no_nul(path)?; |
| 369 | validate_normal_components(path, true)?; |
| 370 | let root = project_root |
| 371 | .canonicalize() |
| 372 | .map_err(|e| TraceDecayError::Config { |
| 373 | message: format!( |
| 374 | "failed to canonicalize project root '{}': {e}", |
| 375 | project_root.display() |
| 376 | ), |
| 377 | })?; |
| 378 | let candidate = if path.is_absolute() { |
| 379 | path.to_path_buf() |
| 380 | } else { |
| 381 | project_root.join(path) |
| 382 | }; |
| 383 | let absolute_path = candidate |
| 384 | .canonicalize() |
| 385 | .map_err(|e| TraceDecayError::Config { |
| 386 | message: format!( |
| 387 | "failed to canonicalize project path '{}': {e}", |
| 388 | candidate.display() |
| 389 | ), |
| 390 | })?; |
| 391 | let relative_path = absolute_path |
| 392 | .strip_prefix(&root) |
| 393 | .map_err(|_| TraceDecayError::Config { |
| 394 | message: format!( |
| 395 | "path '{}' escapes project root '{}'", |
| 396 | path.display(), |
| 397 | project_root.display() |
| 398 | ), |
| 399 | })? |
| 400 | .to_path_buf(); |
| 401 | Ok(Self { |
| 402 | absolute_path, |
| 403 | relative_path, |
| 404 | }) |
| 405 | } |
| 406 | |
| 407 | pub fn absolute_path(&self) -> PathBuf { |
| 408 | self.absolute_path.clone() |