Skip to content
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

Absolute paths on Windows #93

Closed
ofek opened this issue Oct 10, 2017 · 8 comments
Closed

Absolute paths on Windows #93

ofek opened this issue Oct 10, 2017 · 8 comments

Comments

@ofek
Copy link

ofek commented Oct 10, 2017

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

@danielpclark
Copy link

danielpclark commented Oct 10, 2017

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.

@ofek
Copy link
Author

ofek commented Oct 11, 2017

@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.

@sharkdp
Copy link
Owner

sharkdp commented Oct 11, 2017

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

@reima
Copy link
Contributor

reima commented Oct 13, 2017

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

@sharkdp
Copy link
Owner

sharkdp commented Oct 13, 2017

@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)

@reima
Copy link
Contributor

reima commented Oct 13, 2017

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?

@reima
Copy link
Contributor

reima commented Oct 14, 2017

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.

@ofek
Copy link
Author

ofek commented Oct 14, 2017

@reima Great job bug hunting!

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

No branches or pull requests

4 participants