p9 icon indicating copy to clipboard operation
p9 copied to clipboard

p9: overhaul to support new io/fs package in Go 1.16

Open DeedleFake opened this issue 5 years ago • 2 comments

See golang/go#41190 and the documentation.

Unfortunately, the new package only supports read-only filesystems, so a straight implementation of those interfaces won't necessarily make a lot of sense. However, I think that it does make sense to try to get the interfaces to match those in io/fs as much as possible. For example, Remote should probably implement fs.File, and possibly fs.FS as well. Similarly, while it will probably be a bit more awkward, it would be nice if FileSystem, Attachment, and File got changed to embed fs.FS and fs.File, with additions as necessary. Renaming some of them might make sense, too.

DeedleFake avatar Nov 13 '20 19:11 DeedleFake

Plan for Remote

Remote will implement fs.FS, fs.File, and fs.ReadDirFile. Walking will be handled entirely by Open(), and actually opening the file through 9P will be done lazily when Read() or Write() are called. Open() will have to be changed to return an fs.File instead of a *Remote directly, but it'll document that it's just a *Remote underneath, so anyone who's using it directly can just do an assertion.

On top of these changes, DirEntry will be changed to implement both fs.FileInfo and fs.DirEntry. It already mostly implements fs.FileInfo, so this change is fairly minor, but it will require the removal of FileMode in favor of fs.FileMode. This will probably have a couple of annoying edge-cases, but it should simplify things in the long-run.

DeedleFake avatar Nov 18 '20 21:11 DeedleFake

Plan for FileSystem, File, and Attachment

This is slightly trickier. FileSystem is going to stay as it is, but be renamed to Attacher. Auth will become optional to implement via a second interface, Auther. Attacher.Attach(), meanwhile, will be changed to return an fs.FS. File and Attachment will be replaced with fs.File and fs.FS, respectively, with other functionality, such as writing, being relegated to optional interfaces.

An alternative is to provide a function which takes an fs.FS and returns a Attachment, making it relatively easy to just do this manually on the client's end and requiring far fewer changes internally.

DeedleFake avatar Nov 19 '20 06:11 DeedleFake