BurntSushi / walkdir

Rust library for walking directories recursively.
The Unlicense
1.21k stars 106 forks source link

Error from reading a directory without permission doesn't give path #126

Open metsuke0 opened 4 years ago

metsuke0 commented 4 years ago

When iterating over the WalkDir dictionary in Windows 10, rust stable 1.36, if the user does not have permission to read a directory, an error is given, but not the actual path. When hitting an error with files, the path in the error is displayed but not with directories for some reason:

Error on entry 'Err(Error { depth: 2, inner: Io { path: None, err: Os { code: 5, kind: PermissionDenied, message: "Access is denied." } } })': Error { depth: 2, inner: Io { path: None, err: Os { code: 5, kind: PermissionDenied, message: "Access is denied." } } }

    for entry in WalkDir::new(some_path){
        prepath = match &entry {
            Ok(path) => { 
                path
            }
            Err(err) => {
                println!("Error on entry '{:?}': {:?}", entry, err);             
                continue
            }
        };
BurntSushi commented 4 years ago

Hmm, I can't reproduce this on Linux. It will probably be a while before I will debug this on Windows. Others are welcome to investigate and look for a fix sooner.

selfup commented 4 years ago

Yep same here. If I can find some time I'll poke around.

I ran into the same issues with Go/JS. Windows is just really stubborn with this kind of stuff.

Once I get a good entry I get some of those Os errors to when calling fs::metadata.

Even if the permission is correct I do get errors like:

Os { code: 3, kind: NotFound, message: "The system cannot find the path specified." }

and

Os { code: 1920, kind: Other, message: "The file cannot be accessed by the system." }

So I do believe it's mostly a Windows issue.


Here is my code in a repo but it is pretty much the same as above: https://github.com/selfup/win42/blob/master/src/main.rs#L37


However on the unwrap sometimes you get a Some with the path!

Error {
    depth: 21,
    inner: Io {
      path: Some("C:/Users\\selfup\\AppData\\Roaming\\REDACTED"),
      err: Os {
          code: 3,
          kind: NotFound,
          message: "The system cannot find the path specified."
       }
    }
}