-
Notifications
You must be signed in to change notification settings - Fork 119
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
Add fs.FS compatibility converter #184
Conversation
This looks pretty good. I do wish we could have each implementation return FS, so we could get a clean-looking: fs, err := disk.CreateFilesystem(0, diskfs.TypeFat32)
fsys := fs.FS() But the reality is that would be wasteful. It would require every filesystem implementation to implement fs, err := disk.CreateFilesystem(0, diskfs.TypeFat32)
fsys := filesystem.FS(fs) As for naming and structure, I see no need for this to be in its So maybe move this into filesystem. The rest works fine. It does bother me that we cannot just have the returned filesystem from Finally, I am confused by the need for HTTPFS(). That seems extraneous to me. fs, err := disk.CreateFilesystem(0, diskfs.TypeFat32)
fsys := filesystem.FS(fs)
httpfs := http.FS(fsys) Adding the complexity by saving a single call doesn't buy us much. |
Another option might be to move this to an This would mean you'd get something like: fs, err := disk.CreateFilesystem(0, diskfs.TypeFat32)
fsys := fs.FS() But the fat32 implementation's function would just be (using the current naming - this will be changed soon): fat32.go:
func (fat32 *FilSsystem) FS() fs.ReadDirFS {
return converter.FS(fat32)
} The http.Handle("/", http.FileServer(http.FS(converter.FS(fs)))) But I agree, it serves very little purpose, and the naming is horrible ( |
This ready for review? |
Yes, I think so. The only question is whether it's worth adding the |
|
||
type fsFileWrapper struct { | ||
File | ||
stat os.FileInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been using this with read-only images. But if this is to support read/write, then caching the stat
info is probably a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't. fs.FS
currently is read-only. Even its few sub-variants are read-only. If it helps, I have implemented a full read-write FS variant (fs.FS
compatible) which includes support for case-sensitivity and hardlinks and chmod and chown, even on underlying filesystems that do not support it. If you want a link, just ask.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, fs.FS is read-only, but diskfs.FileSystem
can be read/write, so this abstraction could break?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how. fs.FS
is just a subset of what is here. I am comfortable with what it is.
Your contribution is appreciated, @AndreRenaud ! |
This is pretty rudimentary, but it appears to be enough to server the image via
http.FileServer
.There is some poor naming in the code. If this approach appears to be basically acceptable, I'd welcome some feedback on cleaning it up a bit.