perf: use COPYFILE_FICLONE mode when copying files#6461
Conversation
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds the COPYFILE_FICLONE mode flag to file copy operations and ensures the fs.promises.cp call is properly awaited in the server plugin. The change aims to optimize file copying by attempting copy-on-write operations when supported by the filesystem.
- Added
awaitkeyword tofs.promises.cpcall in server plugin - Added
mode: fs.constants.COPYFILE_FICLONEoption to copy operations in both production and test code
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/core/src/plugins/server.ts | Added await to fs.promises.cp and COPYFILE_FICLONE mode for publicDir copying |
| e2e/helper/fixture.ts | Added COPYFILE_FICLONE mode flag to test fixture copy operation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| recursive: true, | ||
| // dereference symlinks | ||
| dereference: true, | ||
| mode: fs.constants.COPYFILE_FICLONE, |
There was a problem hiding this comment.
The mode parameter with COPYFILE_FICLONE is intended for fs.copyFile(), not fs.promises.cp(). When using fs.promises.cp() with recursive: true for directory copying, the mode parameter controls file permissions, not copy behavior flags. Using COPYFILE_FICLONE here may cause the copy operation to fail on filesystems that don't support copy-on-write, or may not have the intended effect. Consider removing this option or handling filesystem compatibility errors explicitly in the catch block.
| mode: fs.constants.COPYFILE_FICLONE, |
| await fse.remove(targetDir); | ||
| await promises.cp(path.join(cwd, 'src'), targetDir, { | ||
| recursive: true, | ||
| mode: fsConstants.COPYFILE_FICLONE, |
There was a problem hiding this comment.
The mode parameter with COPYFILE_FICLONE is intended for fs.copyFile(), not fs.promises.cp(). When using fs.promises.cp() with recursive: true for directory copying, the mode parameter controls file permissions, not copy behavior flags. This could cause test failures on filesystems that don't support copy-on-write. Consider removing this option to ensure test stability across different environments.
| mode: fsConstants.COPYFILE_FICLONE, |

Summary
Leverage
fs.constants.COPYFILE_FICLONEinfs.cpto take advantage of copy-on-write optimizationsThis allows faster file copying when supported by the underlying file system, while gracefully falling back to normal copying on unsupported platforms.
Related Links
modeargument offs.copyFile()tofs.constants.COPYFILE_FICLONEnodejs/node#47861Checklist