facundoolano/rpg-cli

Panics with `.` as argument in Windows

Closed this issue · 6 comments

$ rpg-cli.exe .
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src\location.rs:43:44
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I had similar reports of the program failing in windows when pointing to ~.

Does this happen on PowerShell? with the $HOME env set?

(I'm not familiar with current shell situation in Windows, I didn't expect this to be usable in that OS but maybe it can).

    pub fn go_to(&mut self, dest: &Self) {
        if !dest.path.starts_with(&self.path) {
            println!("dest.path = {:?}", dest.path);
            println!("self.path = {:?}", self.path);
            self.path = self.path.parent().unwrap().to_path_buf();

The output from cargo run -- ....

dest.path = "\\\\?\\C:\\Users\\brian\\Documents\\rpg-cli"
self.path = "C:\\Users\\brian"

     rat[2][xxxx]@C:\Users
...

A caveat with Windows. Some Rust functions convert a path to UNC.

Ideally, for both operating systems, paths meant to be compared should be first converted to UNC / absolute. canonicalize will probably help.

We're actually already using canonicalize, and according to this perhaps that's precisely where the UNC issue originates.

This crate may do the trick https://lib.rs/crates/dunce

@sirwindfield, @Coding-Badly or anyone else interested in running this on windows, it would be useful if you can give it a try with the latest code from main.

It seemed to be fixed in the travis build on Windows but it would be better to get confirmation.

I'll try later on :)