diff options
author | 2023-08-30 18:30:06 -0700 | |
---|---|---|
committer | 2023-08-30 18:30:06 -0700 | |
commit | 0a5d2a8195fbbaab7ff1f40ad54ba94726bcc104 (patch) | |
tree | 218b52f72b1170c8595800dcda34adc312adf08b /src/js/node/fs.promises.ts | |
parent | 89f24e66fff37eab4b984847b73be0b69dbcd0a8 (diff) | |
download | bun-0a5d2a8195fbbaab7ff1f40ad54ba94726bcc104.tar.gz bun-0a5d2a8195fbbaab7ff1f40ad54ba94726bcc104.tar.zst bun-0a5d2a8195fbbaab7ff1f40ad54ba94726bcc104.zip |
feat(node:fs): add `cp`/`cpSync`/`promises.cp` + async `copyFile` (#4340)
* half working disaster code
* this
* async copyFile
* .
* its failing symlink tests
* asdfg
* asdf
* hmm
* okay i think ti works
* small edits
* fix test on linux
* i hate atomics / atomics hate me back <3
* add a message in the builtins bundler that 0.8 is needed. it breaks on older versions lol.
* fixed
* rebase
Diffstat (limited to 'src/js/node/fs.promises.ts')
-rw-r--r-- | src/js/node/fs.promises.ts | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/js/node/fs.promises.ts b/src/js/node/fs.promises.ts index 406858f7f..dfc24cae7 100644 --- a/src/js/node/fs.promises.ts +++ b/src/js/node/fs.promises.ts @@ -89,11 +89,28 @@ function watch( }; } +let lazy_cp: any = null; +// attempt to use the native code version if possible +// and on MacOS, simple cases of recursive directory trees can be done in a single `clonefile()` +// using filter and other options uses a lazily loaded js fallback ported from node.js +function cp(src, dest, options) { + if (!options) return fs.cp(src, dest); + if (typeof options !== "object") { + throw new TypeError("options must be an object"); + } + if (options.dereference || options.filter || options.preserveTimestamps || options.verbatimSymlinks) { + if (!lazy_cp) lazy_cp = require("../internal/fs/cp-sync"); + return lazy_cp!(src, dest, options); + } + return fs.cp(src, dest, options.recursive, options.errorOnExist, options.force ?? true, options.mode); +} + export default { access: promisify(fs.accessSync), appendFile: promisify(fs.appendFileSync), close: promisify(fs.closeSync), - copyFile: promisify(fs.copyFileSync), + copyFile: fs.copyFile.bind(fs), + cp, exists: promisify(fs.existsSync), chown: promisify(fs.chownSync), chmod: promisify(fs.chmodSync), |