Load and parse a `.dockerignore` file from the context directory. Returns an empty list if no `.dockerignore` exists.
(context_dir: &Path)
| 338 | /// |
| 339 | /// Returns an empty list if no `.dockerignore` exists. |
| 340 | fn load_dockerignore(context_dir: &Path) -> Vec<IgnorePattern> { |
| 341 | let dockerignore_path = context_dir.join(".dockerignore"); |
| 342 | let Ok(contents) = std::fs::read_to_string(&dockerignore_path) else { |
| 343 | return Vec::new(); |
| 344 | }; |
| 345 | |
| 346 | contents |
| 347 | .lines() |
| 348 | .map(str::trim) |
| 349 | .filter(|line| !line.is_empty() && !line.starts_with('#')) |
| 350 | .map(|line| { |
| 351 | line.strip_prefix('!').map_or_else( |
| 352 | || IgnorePattern { |
| 353 | pattern: line.to_string(), |
| 354 | negated: false, |
| 355 | }, |
| 356 | |rest| IgnorePattern { |
| 357 | pattern: rest.trim().to_string(), |
| 358 | negated: true, |
| 359 | }, |
| 360 | ) |
| 361 | }) |
| 362 | .collect() |
| 363 | } |
| 364 | |
| 365 | /// Check whether a relative path should be ignored based on `.dockerignore` patterns. |
| 366 | /// |
no test coverage detected