-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: os: Provide the inverse of DirFS(string) #57546
Comments
ISTM you could make a struct that records the original file path but embeds an fs.FS and just use that. It doesn’t seem like a common enough use case that you need to worry about someone outside your application passing you an fs.FS of unknown provenance. That said, maybe there could be an optional method URI() for an FS to implement that returns s3://bucket mem:// file:///path etc. |
this looks a bit like poor design, where the thing you test isn't the same as the thing running in production. fwiw, reflect works |
This is exactly what I ended up with before filing this issue. I thought it could be useful to have a common way to check if the FS is local and real.
Or a
Uh, is that a bad thing? After all |
This is easy to do for specific uses. Is it really such a common use case that it should be added to the standard library? Can you show some existing examples that would benefit form this? |
Just as
os.DirFS(string)
returns an fs.FS implementation based on the path passed, the inverse operation (fs.FS -> string) should be provided.Possible use case
Suppose we have a repository-like struct. This repo returns a different path depending on whether the fs.FS is a real OS file system, or any other "virtual" file systems (e.g. a testing one, or a network fs like S3).
Possible solution
Simply export the
os.dirFS
. This way, we canpath, ok := fs.(os.DirFS)
.The text was updated successfully, but these errors were encountered: