From abf7fd1ff34987f858cdcd4949d182e07a935eec Mon Sep 17 00:00:00 2001 From: Monica Olejniczak Date: Tue, 30 Jul 2024 18:54:42 +1000 Subject: [PATCH] Update canonicalize --- .../src/in_memory_file_system.rs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/crates/parcel_filesystem/src/in_memory_file_system.rs b/crates/parcel_filesystem/src/in_memory_file_system.rs index 428a8e769d8..8915dacc6de 100644 --- a/crates/parcel_filesystem/src/in_memory_file_system.rs +++ b/crates/parcel_filesystem/src/in_memory_file_system.rs @@ -42,21 +42,25 @@ impl InMemoryFileSystem { } fn canonicalize_impl(&self, path: &Path) -> PathBuf { - let cwd = self.current_working_directory.read().unwrap(); - let mut result = if path.is_absolute() { - vec![] - } else { - cwd.components().collect() - }; - - let components = path.components(); - for component in components { + let mut path = path.to_path_buf(); + if path.is_relative() { + path = self + .current_working_directory + .read() + .unwrap() + .to_path_buf() + .join(path); + } + + let mut result = Vec::new(); + + for component in path.components() { match component { Component::Prefix(prefix) => { - result = vec![Component::Prefix(prefix)]; + result.push(Component::Prefix(prefix)); } Component::RootDir => { - result = vec![Component::RootDir]; + result.push(Component::RootDir); } Component::CurDir => {} Component::ParentDir => {