Skip to content

On Windows, mkdir -p and add_file/add_dir key implicit parent directories with \ #2830

Closed

Description

@CameronTofer

Version: 0.20.3, InMemoryFs, Windows host. Follow-up to #2425 / #2435.

Repro

let fs = Arc::new(InMemoryFs::new());
let mut sh = Bash::builder().fs(fs.clone()).cwd("/tmp").build();
sh.exec("mkdir -p a/b; mkdir c").await?;
// fs.snapshot() paths on Windows: "/tmp\a", "/tmp\a\b", "/tmp/c"

Lookups still work, because they normalize. But snapshot() exposes the \ keys, so a caller that maps snapshot paths back to / paths loses every directory that mkdir -p created.

Cause

src/fs/memory.rs builds parent paths with current.push(component) in four places:

  • add_file (line 935)
  • add_dir (line 1023)
  • add_lazy_file (line 1101)
  • recursive mkdir (line 1486)

PathBuf::push adds the host separator. #2435 closed this class for Path::join and rated the remaining push sites "normalized downstream — consistency, not a live bug". Here, though, the pushed path becomes an entry-map key directly. That's the same shape as the InMemoryFs::rename fan-out the PR fixed.

Fix

Use the helper the file already imports, at all four sites:

-                current.push(component);
+                current = vfs_join(&current, component);

Tested against 0.20.3 on Windows: cargo test --lib fs:: passes 224/224, and our downstream filesystem tests pass 10/10 with this patch in place of our workaround.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions