nodejs / nodejs/node

fs: Change the default value of `mode` argument of `fs.copyFile()` to `fs.constants.COPYFILE_FICLONE`

未关闭
#47,861 9 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

feature request fs never-stale
主要语言
JavaScript
星标
122k
派生
37.3k
平均合并
4 天 2 小时
30 天内合并 PR
283

描述

What is the problem this feature will solve?

Today's operating systems and some file systems supports copy-on-write operation for copying a file (e.g. btrfs on Linux, APFS on Apple's Darwins).

fs.copyFile() has already supported them as opt-in behavior if the underlying platform support such operations and libuv support them.

However, it's still opt-in behavior.

The default value of mode argument. of fs.copyFile() is 0. This mean that fs.copyFile() does not use copy-on-write and use traditional copying mechanism operation even if the underlying platform and libuv supports such operation.

An user can use copy-on-write operation by passingfs.constants.COPYFILE_FICLONE to mode argument.

But if we forget to pass it, fs.copyFile() does not use an enhancement underlying mechanism. We (all programmers) tend to forget to supply a such optional flag to API and to lose a chance to improve a performance. I think this is a bug for API egonomics and having a value we should fix.

What is the feature you are proposing to solve the problem?

My proposal is changing the default value of mode argument of fs.copyFile() to fs.constants.COPYFILE_FICLONE from 0.

By this change, all exist programs using fs.copyFile() in all over the world can get a chance to improve their throughput without any code change.

If the underlying platform does not support copy-on-write behavior, then fs.constants.COPYFILE_FICLONE flag fallback into the traditional approach. I think this change is painless approach.

fs.constants.COPYFILE_FICLONE: The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then a fallback copy mechanism is used.

https://nodejs.org/api/fs.html#fspromisescopyfilesrc-dest-mode

What alternatives have you considered?
  1. This change might be a "breaking change" if we think it strictly. If there is a user program expect fs.copyFile() copy a file without copy-on-write, this change would be problematic.
    • I think it's not be a problem to change a file copying mechanism for user program. It's an abstracted problem by a platform (Node.js, operation system, and file system). An user program should be agnostic about it.
    • But I'm not sure about the Node.js' committee's breaking change policy, I note about this point as a consideration.
  2. This also affects the behavior of other APIs that uses fs.copyFile() internally (e.g. fs.cp()).

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

审查 fs.copyFile() API 和 fs.constants.COPYFILE_FICLONE 的行为,然后检查 libuv 的 src/unix/fs.c 实现。在决定哪些测试和文档可以定义完成标准之前,考虑相关的 fs.cp() 行为和兼容性影响。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
api, operating-systems
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。