Should the FS returned by os.DirFS implement StatFS?

340 views
Skip to first unread message

ben...@gmail.com

unread,
Feb 15, 2021, 4:04:16 PM2/15/21
to golang-dev
Josh Bleecher Snyder noted on the #performance Gopher Slack channel:

> Also, surprisingly (to me), os.DirFS doesn't implement fs.StatFS, so it has to fall back to opening the file first.

This seems like an oversight, or are we missing something? It still works, of course, but it has to do the extra work of opening the file first and closing it after, rather than just calling os.Stat directly.

If folks agree this should be added, I'm happy to submit a patch. Would this go in 1.16 as io/fs is new functionality anyway (presumably not)?

-Ben

Brandon Bloom

unread,
Jul 22, 2021, 3:14:41 PM7/22/21
to golang-dev
I just encountered this as well and found it surprising:

panic: interface conversion: os.dirFS is not fs.StatFS: missing method Stat

Damien Neil

unread,
Jul 22, 2021, 3:52:16 PM7/22/21
to Brandon Bloom, golang-dev
In Go 1.17, the FS returned by os.DirFS implements fs.StatFS.

Added in:

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-dev/c61a7ab1-1059-4da3-a66e-2da80ead67f6n%40googlegroups.com.

Brandon Bloom

unread,
Jul 22, 2021, 4:55:19 PM7/22/21
to golang-dev
Great news! Thank you.
Reply all
Reply to author
Forward
0 new messages