google / renameio

Package renameio provides a way to atomically create or replace a file or symbolic link.
Apache License 2.0
609 stars 27 forks source link

fs.FS support? #37

Closed ainar-g closed 3 years ago

ainar-g commented 3 years ago

Considering that the package is quite low-level at times, would it be at all possible to add support for the fs.FS interface? For example, to have versions of TempDir and TempFile that accept fs.FS? And perhaps the latter would return a modified version of fs.File?

stapelberg commented 3 years ago

I have only used fs.FS when working with the embed package thus far, so my experience with it is limited.

When you suggest adding a version of TempFile that accepts fs.FS, what sort of use-cases would that make possible? Can you provide an example or a specific motivation?

renameio needs os.OpenFile (to create a new file), (*os.File).Sync and os.Rename. AFAICT, fs.FS offers none of these, so we’d need to use interface assertions, or a custom interface to begin with.

twpayne commented 3 years ago

fs.FS only supports read-only filesystems, and so is not suitable for renameio.

ainar-g commented 3 years ago

I was under a false impression that package io/fs provided extension interfaces for writable filesystems, but I now see that that is not the case. Apologies for the noise.