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

os: Readdir fails, if one of the files cannot be accessed #11235

Closed
bancek opened this issue Jun 16, 2015 · 1 comment
Closed

os: Readdir fails, if one of the files cannot be accessed #11235

bancek opened this issue Jun 16, 2015 · 1 comment

Comments

@bancek
Copy link

bancek commented Jun 16, 2015

If directory contains file that cannot be accessed (if lstat fails), f.Readdir fails with an error.

Error can be reproduced using custom FUSE driver.

https://gist.github.com/bancek/4adadd65597a2da44a49

Bash fails to show info for that dir but still lists other files.

$ mkdir foo bar
$ ./deny foo
$ ls -al
ls: cannot access foo: Permission denied
total 20
drwxrwxr-x   4 luka luka  4096 Jun 16 17:28 .
drwxrwxr-x 233 luka luka 12288 Jun 16 16:26 ..
drwxrwxr-x   2 luka luka  4096 Jun 16 17:28 bar
d?????????   ? ?    ?        ?            ? foo

Readdir fails with lstat permission denied (http://play.golang.org/p/G_yZ94rkRs).

$ go run ../readdirtest.go 
panic: lstat ./foo: permission denied

Readdirnames works fine (http://play.golang.org/p/WY-uBxCjpd).

$ go run ../readdirnamestest.go 
[foo bar]
@bradfitz
Copy link
Contributor

This is working as designed and documented: "In this case, if Readdir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdir returns the FileInfo read until that point and a non-nil error."

I think you already found the answer: use Readdirnames.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants