Skip to content

Commit

Permalink
Use copy on write when available.
Browse files Browse the repository at this point in the history
  • Loading branch information
rictic committed Oct 13, 2023
1 parent 83ae668 commit b266901
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/util/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ export const copyEntries = async (
*/
const copyFileGracefully = async (src: string, dest: string): Promise<void> => {
try {
await fs.copyFile(src, dest, fs.constants.COPYFILE_EXCL);
await fs.copyFile(
src,
dest,
// COPYFILE_FICLONE: Copy the file using copy-on-write semantics, so that
// the copy takes constant time and space. This is a noop currently
// on some platforms, but it's a nice optimization to have.
// See https://github.com/libuv/libuv/issues/2936 for macos support.
fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE,
);
} catch (error) {
const {code} = error as {code: string};
if (code === /* does not exist */ 'ENOENT') {
Expand Down

0 comments on commit b266901

Please sign in to comment.