Skip to content

Commit

Permalink
test(fs-index): avoid canonicalization on windows
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <tareknaser360@gmail.com>
  • Loading branch information
tareknaser committed Aug 3, 2024
1 parent 511e718 commit c962677
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 10 additions & 5 deletions fs-index/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,20 @@ impl<Id: ResourceId> ResourceIndex<Id> {
pub fn build<P: AsRef<Path>>(root_path: P) -> Result<Self> {
log::debug!("Building index at root path: {:?}", root_path.as_ref());

// Canonicalize the root path
let root = fs::canonicalize(&root_path)?;
let root_path = root_path.as_ref();
// Canonicalize the root path (only for unix-like systems)
// Note: On windows, canonicalization adds a prefix to the path
// which breaks the path comparison in the tests
#[cfg(target_family = "unix")]
let root_path = root_path.canonicalize()?;

let mut id_to_paths: HashMap<Id, HashSet<PathBuf>> = HashMap::new();
let mut path_to_resource = HashMap::new();

// Discover paths in the root directory
let paths = discover_paths(&root)?;
let paths = discover_paths(&root_path)?;
let entries: HashMap<PathBuf, ResourceIdWithTimestamp<Id>> =
scan_entries(&root, paths);
scan_entries(&root_path, paths);

// Strip the root path from the entries
let entries: HashMap<PathBuf, ResourceIdWithTimestamp<Id>> = entries
Expand All @@ -309,7 +314,7 @@ impl<Id: ResourceId> ResourceIndex<Id> {
path_to_resource.extend(entries.clone());

let index = ResourceIndex {
root,
root: root_path.to_path_buf(),
id_to_paths,
path_to_resource,
};
Expand Down
2 changes: 0 additions & 2 deletions fs-index/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ fn test_build_index_with_directory() {
.expect("Failed to get resource");
assert_eq!(
resource, expected_resource,
"{:?} != {:?}",
resource, expected_resource
);
});
}
Expand Down

0 comments on commit c962677

Please sign in to comment.