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: add CopyFS #62484
Comments
Why is the |
This seems related to #56172. There's a similar question in these about how to handle broken writes and missing directories. |
Maybe for this and #56172 there could be a "create directories" argument. Maybe it could be a mode and if the mode is non-zero directories are created. For os.CopyFS, the mode could be &'d with the mode of the source directory. Maybe there should also be os.CopyFSFile to just copy one fs.File. |
This proposal has been added to the active column of the proposals project |
In #56172 AFAICT the consensus was that the copy operation should attempt to use FICLONE (or equivalent) whenever possible; this does not currently seem to be captured in this superseding proposal though. |
There are questions about whether to create directories, modes, and so on. If we go down that road, it should be a third-party package (lots of them) so that everyone can use the combination they want. The basic os.CopyFS should be the simple one that's good enough the other 99% of the time. In theory os.CopyFS could detect an os.DirFS source and use its own special-case code to take advantage of FICLONE if that was an important optimization. |
Have all remaining concerns about this proposal been addressed? |
The sample code has |
I think it should use 0777, the same way that os.OpenFile uses 0666. Let the umask set the permissions, same as if we were using the shell's mkdir and 'cat >file'. The only bits being copied out are the execute bits on regular files. |
I think the complete docs for CopyFS are:
|
Should switch m := d.Mode(); {
case m.IsRegular():
...
case m&os.ModeSymlink != 0:
link, err := os.Readlink(path)
if err != nil {
return err
}
if err := os.Symlink(link, targ); err != nil {
return err
}
} If so, we should make sure that it works reasonable well with Windows symbolic links, or at least that the outcome is well understood and consistent. This is related to #63703. |
It's very unclear to me what CopyFS should do with symlinks. Perhaps we should un-accept #49580. :-) |
Symbolic links are so awful. I am going to come back to this after Go 1.22 is frozen. |
After discussion on #45757 (comment) and #61386, it would help many different use cases to add os.CopyFS that copies an fsys.FS into the local file system, safely. I propose to add that function.
The signature and implementation are roughly:
with perhaps some extra checks using filepath.IsLocal to guard against bad file names.
The text was updated successfully, but these errors were encountered: