Skip to content

Commit

Permalink
fixup! fs: fs.cp() should accept mode flag to specify the copy be…
Browse files Browse the repository at this point in the history
…havior
  • Loading branch information
tetsuharuohzeki committed Mar 16, 2023
1 parent 1b4e164 commit 3451bbe
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions test/parallel/test-fs-cp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,27 @@ function nextdir() {

// It copies a nested folder structure with mode flags.
// This test is based on fs.promises.copyFile() with `COPYFILE_FICLONE_FORCE`.
{
(() => {
const src = './test/fixtures/copy/kitchen-sink';
const dest = nextdir();
try {
cpSync(src, dest, mustNotMutateObjectDeep({
recursive: true,
mode: fs.constants.COPYFILE_FICLONE_FORCE,
}));
assertDirEquivalent(src, dest);
// If the platform support `COPYFILE_FICLONE_FORCE` operation,
// it should reach to here.
} catch (err) {
// If the platform does not support `COPYFILE_FICLONE_FORCE` operation,
// it should enter this path.
assert.strictEqual(err.syscall, 'copyfile');
assert(err.code === 'ENOTSUP' || err.code === 'ENOTTY' ||
err.code === 'ENOSYS' || err.code === 'EXDEV');
return;
}
}

// If the platform support `COPYFILE_FICLONE_FORCE` operation,
// it should reach to here.
assertDirEquivalent(src, dest);
})();

// It does not throw errors when directory is copied over and force is false.
{
Expand Down Expand Up @@ -875,26 +877,29 @@ if (!isWindows) {

// It copies a nested folder structure with mode flags.
// This test is based on fs.promises.copyFile() with `COPYFILE_FICLONE_FORCE`.
{
await (async () => {
const src = './test/fixtures/copy/kitchen-sink';
const dest = nextdir();
let p;
try {
const p = await fs.promises.cp(src, dest, mustNotMutateObjectDeep({
p = await fs.promises.cp(src, dest, mustNotMutateObjectDeep({
recursive: true,
mode: fs.constants.COPYFILE_FICLONE_FORCE,
}));
assert.strictEqual(p, undefined);
assertDirEquivalent(src, dest);
// If the platform support `COPYFILE_FICLONE_FORCE` operation,
// it should reach to here.
} catch (err) {
// If the platform does not support `COPYFILE_FICLONE_FORCE` operation,
// it should enter this path.
assert.strictEqual(err.syscall, 'copyfile');
assert(err.code === 'ENOTSUP' || err.code === 'ENOTTY' ||
err.code === 'ENOSYS' || err.code === 'EXDEV');
return;
}
}

// If the platform support `COPYFILE_FICLONE_FORCE` operation,
// it should reach to here.
assert.strictEqual(p, undefined);
assertDirEquivalent(src, dest);
})();

// It accepts file URL as src and dest.
{
Expand Down

0 comments on commit 3451bbe

Please sign in to comment.