Skip to content

Commit 9bfeb33

Browse files
authored
Fix resolve_globs crash when at root directory (#15988)
Fixes a crash found in Dockerfiles when a build takes place at the root directory. It's not a good practice to keep your application logic in `/`, but it probably shouldn't cause a crash either. I found this particularly difficult to write tests for because it would involve either running a glob on my real filesystem starting from `/` or mocking the calls to `fs` which as far as I can tell isn't supported in the codebase and would be out of scope to try to do here. Fixes #15987
1 parent f237f59 commit 9bfeb33

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

crates/oxide/src/scanner/detect_sources.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,16 @@ impl DetectSources {
112112
continue;
113113
}
114114

115-
// If we are in a directory where the parent is a forced static directory, then this
116-
// will become a forced static directory as well.
117-
if forced_static_directories.contains(&entry.path().parent().unwrap().to_path_buf())
118-
{
119-
forced_static_directories.push(entry.path().to_path_buf());
120-
root_directories.insert(entry.path().to_path_buf());
121-
continue;
115+
// Although normally very unlikely, if running inside a dockerfile
116+
// the current directory might be "/" with no parent
117+
if let Some(parent) = entry.path().parent() {
118+
// If we are in a directory where the parent is a forced static directory, then this
119+
// will become a forced static directory as well.
120+
if forced_static_directories.contains(&parent.to_path_buf()) {
121+
forced_static_directories.push(entry.path().to_path_buf());
122+
root_directories.insert(entry.path().to_path_buf());
123+
continue;
124+
}
122125
}
123126

124127
// If we are in a directory, and the directory is git ignored, then we don't have to

0 commit comments

Comments
 (0)