Fd: Absolute paths on Windows

Created on 10 Oct 2017  路  8Comments  路  Source: sharkdp/fd

I currently get 2 extra path separators after the drive e.g. C:\\\Users\Ofek\Desktop\... which does not work in Windows.

Windows 7:
capture

Windows 10:
w10

bug help wanted

Most helpful comment

The bug is in the colored output (which I disabled in my examples). The problem is that the first std::path::Components of an absolute path on Windows are Prefix(_) (the drive letter) and RootDir (root of the drive). The string value of RootDir is the path separator \. So the three consecutive path separators are:

  • The path separator after the prefix
  • The root dir
  • The path separator after the root dir

I'll make a PR in a bit.

All 8 comments

According to Microsoft:

Note File I/O functions in the Windows API convert / to \ as part of converting the name to an NT-style name, except when using the \\?\ prefix as detailed in the following sections.

Source: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

And the Ruby language uses forward slashes for File paths and that works on Windows.

@sharkdp Upon further inspection, it appears that this is something specific to fd. The \\?\ is correctly removed but I don't know where those 2 extra separators come from.

use std::path::Path;

fn main() {
    let path = Path::new("C:/Users/Ofek");
    println!("{}", path.canonicalize().unwrap().display());
}

yields \\?\C:\Users\Ofek.

This might come from using Path::join.. but that's just a guess. Will take a closer look soon.

Has this already been fixed? I can't repro this behavior on Windows 10.

E:\Development\Rust\Projects\fd>ver

Microsoft Windows [Version 10.0.15063]

E:\Development\Rust\Projects\fd>rustc --version
rustc 1.21.0 (3b72af97e 2017-10-09)

E:\Development\Rust\Projects\fd>git rev-parse --short HEAD
8fc3a83

E:\Development\Rust\Projects\fd>target\debug\fd.exe -a -c never
E:\Development\Rust\Projects\fd\CONTRIBUTING.md
E:\Development\Rust\Projects\fd\Cargo.lock
E:\Development\Rust\Projects\fd\Cargo.toml
E:\Development\Rust\Projects\fd\LICENSE
E:\Development\Rust\Projects\fd\README.md
E:\Development\Rust\Projects\fd\appveyor.yml
E:\Development\Rust\Projects\fd\build.rs
E:\Development\Rust\Projects\fd\src
E:\Development\Rust\Projects\fd\src\app.rs
E:\Development\Rust\Projects\fd\src\fshelper
E:\Development\Rust\Projects\fd\src\fshelper\mod.rs
E:\Development\Rust\Projects\fd\src\internal.rs
E:\Development\Rust\Projects\fd\src\lscolors
E:\Development\Rust\Projects\fd\src\lscolors\mod.rs
E:\Development\Rust\Projects\fd\src\main.rs
E:\Development\Rust\Projects\fd\src\output.rs
E:\Development\Rust\Projects\fd\src\walk.rs
E:\Development\Rust\Projects\fd\tests
E:\Development\Rust\Projects\fd\tests\testenv
E:\Development\Rust\Projects\fd\tests\testenv\mod.rs
E:\Development\Rust\Projects\fd\tests\tests.rs

@reima Thank you for the feedback. It has not been fixed.

I'm not sure, but this issue might only appear if an explicit search path is given (like in target\debug\fd.exe -c never E:\Development)

It works for me even with an explicit path:

E:\Development\Rust\Projects\fd>target\debug\fd.exe -c never . E:\\Development\\Rust\\Projects\\fd
E:\Development\Rust\Projects\fd\CONTRIBUTING.md
E:\Development\Rust\Projects\fd\Cargo.lock
E:\Development\Rust\Projects\fd\Cargo.toml
E:\Development\Rust\Projects\fd\LICENSE
E:\Development\Rust\Projects\fd\README.md
E:\Development\Rust\Projects\fd\appveyor.yml
E:\Development\Rust\Projects\fd\build.rs
E:\Development\Rust\Projects\fd\src
E:\Development\Rust\Projects\fd\src\app.rs
E:\Development\Rust\Projects\fd\src\fshelper
E:\Development\Rust\Projects\fd\src\fshelper\mod.rs
E:\Development\Rust\Projects\fd\src\internal.rs
E:\Development\Rust\Projects\fd\src\lscolors
E:\Development\Rust\Projects\fd\src\lscolors\mod.rs
E:\Development\Rust\Projects\fd\src\main.rs
E:\Development\Rust\Projects\fd\src\output.rs
E:\Development\Rust\Projects\fd\src\walk.rs
E:\Development\Rust\Projects\fd\tests
E:\Development\Rust\Projects\fd\tests\testenv
E:\Development\Rust\Projects\fd\tests\testenv\mod.rs
E:\Development\Rust\Projects\fd\tests\tests.rs

@ofek Can you please tell us how to reproduce this issue?

The bug is in the colored output (which I disabled in my examples). The problem is that the first std::path::Components of an absolute path on Windows are Prefix(_) (the drive letter) and RootDir (root of the drive). The string value of RootDir is the path separator \. So the three consecutive path separators are:

  • The path separator after the prefix
  • The root dir
  • The path separator after the root dir

I'll make a PR in a bit.

@reima Great job bug hunting!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChengCat picture ChengCat  路  3Comments

ariecattan picture ariecattan  路  3Comments

mathomp4 picture mathomp4  路  4Comments

kclevenger picture kclevenger  路  3Comments

Dietr1ch picture Dietr1ch  路  3Comments