A new uv_fs_copyfile
function recently landed in libuv in order to allow more efficient copying of files (in the future, it could allow copy-on-write semantics on file systems that support it). A copyFile function that uses this should be added to Node.js. 馃槂
Depends on upgrade to libuv 1.14.0 (#14866)
I'll be working on this once libuv can be updated. Right now, it's blocked on a broken test.
Thank you @cjihrig! I just wanted to create an issue for tracking purposes 馃槂
Could someone detail the advantages of uv_fs_copyfile
?
Do note that we make no guarentees to expose every libuv API. 馃槈
Could someone detail the advantages of uv_fs_copyfile?
Two main advantages:
Copy-on-write needs native system calls to function, as the hacky mechanism used in Node.js projects at the moment (read the input file into a buffer and write it to the new location) is not recognised as a file copy by the OS. The file system just sees it as creation of a brand new file.
One thing to keep an eye out for. Replacing a JS implementation with a native API for file system related stuff will end up changing the underlying syscall failures if anything goes wrong. We saw this happen with realpath, and things got weird quickly.
This is in no way saying we shouldn't do this, but we should be pretty thorough with smoke testing if we do decide to change things. Either way it will likely be semver major, even if not obviously so
We aren't replacing anything here though. This would be purely semver minor for core. The applications using it can pick their own level of semver.
. Replacing a JS implementation with a native API
There is no core JS implementation at the moment. This would add a brand new function, so there's no breaking change. Currently, apps are implementing their own JS versions of it.
Existing https://github.com/nodejs/node/issues/12902 requests the same feature.
I am in favor of implementing this on core :+1:
Most helpful comment
Two main advantages:
Copy-on-write needs native system calls to function, as the hacky mechanism used in Node.js projects at the moment (read the input file into a buffer and write it to the new location) is not recognised as a file copy by the OS. The file system just sees it as creation of a brand new file.