Repository navigation
Add fs.cpSync, fs.cp and fs/promises cp - #1166
Merged
Merged
Conversation
fs.cpSync, fs.cp and fs/promises cp compile with every option: dereference, errorOnExist, filter, force, mode, preserveTimestamps, recursive and verbatimSymlinks. They follow Node's two implementations. cpSync follows cp-sync.js over the fs binding: copy errors are plain Errors with a code, std::error_code failures throw an ErrnoException, and links inside a copied directory point at their canonical targets. fs.cp and fs/promises cp follow cp.js, whose copy errors are SystemErrors with code, info, errno, syscall and path. Options and paths validate in Node's order with Node's errors. filter runs for the top-level paths and each entry in Node's order; an async filter must return a promise that is already settled, and a pending one throws SC2020. The callback and promise forms complete the copy before the callback runs or the promise settles. Windows builds throw SC2020. The copy lives in the new scr_fs_cp.c. Directory walks keep their frames on the heap, so deep trees also copy on a fiber's stack. File contents copy with sendfile on Linux, and COPYFILE_FICLONE uses FICLONE where it exists. ScrError gains the SystemError context and the ErrnoException key order, with matching fields in the compiler's Error layout. The stored fs.cp callback uses the same implementation. Corpus 5567-5571 cover the sync, callback and promise forms, errors, symlinks and 1500-level trees.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
std::filesystem::copy_file reports a destination that exists but is not a regular file as invalid_argument in libstdc++ and as not_supported in libc++, which Node's macOS builds use. cpSync on Apple platforms now throws ENOTSUP there, as Node does, and the fs errno names include ENOTSUP. Corpus 5571 copies a 400-level directory chain instead of 1500 levels, so its deepest path stays under macOS's 1024-byte PATH_MAX.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
info, errno, syscall, path) and native-binding error shapes to the runtime.fs/promisescpof 5 x 2,000 files: 184 ms against Node's 1,436 ms;cpSyncmatches Node (171 ms against 166 ms).