-
-
Notifications
You must be signed in to change notification settings - Fork 534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(biome_fs): make paths absolute to correctly match against globs #5017
Conversation
CodSpeed Performance ReportMerging #5017 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do wonder if we can’t fix MemoryFS
instead. I recently wrote a few tests with it where I used absolute paths instead and it worked fine. So I suspect the issue isn’t so much that absolute paths can’t work there, just that many tests are written to assume relative paths. I understand it would be painful to update those tests, but it would give us better coverage and better performance.
crates/biome_fs/src/fs/os.rs
Outdated
@@ -234,6 +235,12 @@ impl<'scope> OsTraversalScope<'scope> { | |||
|
|||
impl<'scope> TraversalScope<'scope> for OsTraversalScope<'scope> { | |||
fn evaluate(&self, ctx: &'scope dyn TraversalContext, path: Utf8PathBuf) { | |||
let path = match std::path::Path::new(&path).absolutize() { | |||
Ok(std::borrow::Cow::Owned(absolutized)) => { | |||
Utf8PathBuf::from_path_buf(absolutized).unwrap_or(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using unwrap_or()
may make it very hard to debug if there is ever an issue with an absolute path, since it means we’ll unexpectedly pass a relative path instead. I’d just use .expect()
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would appreciate we could, at least, add one test that covers the issue we're trying to fix.
We already have tests that use the OS file system:
biome/crates/biome_cli/tests/commands/lint.rs
Lines 896 to 916 in be56c2e
let _ = remove_dir_all(&root_path); | |
create_dir_all(&subdir1_path).unwrap(); | |
create_dir_all(&subdir2_path).unwrap(); | |
#[cfg(target_family = "unix")] | |
{ | |
symlink(&subdir2_path, subdir1_path.join("symlink1")).unwrap(); | |
symlink(subdir1_path, subdir2_path.join("symlink2")).unwrap(); | |
} | |
#[cfg(target_os = "windows")] | |
{ | |
check_windows_symlink!(symlink_dir(&subdir2_path, &subdir1_path.join("symlink1"))); | |
check_windows_symlink!(symlink_dir(subdir1_path, subdir2_path.join("symlink2"))); | |
} | |
let result = run_cli( | |
DynRef::Owned(Box::new(OsFileSystem::new(root_path.clone()))), | |
&mut console, | |
Args::from([("lint"), (root_path.display().to_string().as_str())].as_slice()), | |
); |
@ematipico However, it is not possible to declare a working directory with |
The argument that you pass to biome/crates/biome_cli/tests/commands/lint.rs Lines 808 to 811 in 2696970
biome/crates/biome_fs/src/fs/os.rs Lines 30 to 39 in 7f6d37d
|
b603e76
to
f228d10
Compare
dbg!(&path); | ||
let path = match std::path::Path::new(&path).absolutize() { | ||
Ok(std::borrow::Cow::Owned(absolutized)) => Utf8PathBuf::from_path_buf(absolutized) | ||
.expect("Absolute path must be correctly parsed"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully this panic won't bite us
64552d3
to
bd79c92
Compare
I agree. Feel free to investigate the case once the PR merged. |
I added an end-to-end test. Once the CI passes, I will merge the PR. |
Summary
We recently added a normalization step before matching against glob pattern.
The normalization step strips the working directory from checked evaluated path.
Some passed paths are not absolute making it impossible to properly normalize.
This PR fixes the issue, by converting relative paths passed to the CLI into absolute paths.
I first modified the
traverse_inputs
function inbiome_cli/src/traverse.rs
.The fix was correct, however this makes fails the implementation of
MemoryFs
that assumes relative paths.Thus, I moved the fix to
OsTraversalScope::evaluate
inbiome_fs/src/fs/os.rs
.This may make the fix less performant.
It is not the first time I encounter issues with our memory FS.
I wonder if we should not remove this abstraction and directly use a temporary folder for each test.
This could have the nice effect of actually testing real code paths and to identify bugs like the one this PR fixes.
Test Plan
I manually tested the fix.
It isn't possible to test it with memory fs because the change is in the os filesystem.