We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d2931e5 commit 996fdb0Copy full SHA for 996fdb0
2 files changed
lib/internal/fs/cp/cp.js
@@ -54,6 +54,7 @@ const {
54
resolve,
55
sep,
56
} = require('path');
57
+const fsBinding = internalBinding('fs');
58
59
async function cpFn(src, dest, opts) {
60
// Warn about using preserveTimestamps on 32-bit node
@@ -344,7 +345,10 @@ async function onLink(destStat, src, dest, opts) {
344
345
if (!isAbsolute(resolvedDest)) {
346
resolvedDest = resolve(dirname(dest), resolvedDest);
347
}
- if (isSrcSubdir(resolvedSrc, resolvedDest)) {
348
+
349
+ const srcIsDir = fsBinding.internalModuleStat(src) === 1;
350
351
+ if (srcIsDir && isSrcSubdir(resolvedSrc, resolvedDest)) {
352
throw new ERR_FS_CP_EINVAL({
353
message: `cannot copy ${resolvedSrc} to a subdirectory of self ` +
354
`${resolvedDest}`,
test/parallel/test-fs-cp.mjs
@@ -248,7 +248,7 @@ function nextdir(dirname) {
248
);
249
250
251
-// It allows copying when is not a directory
+// It allows cpSync copying symlinks in src to locations in dest with existing synlinks not pointing to a directory.
252
{
253
const src = nextdir();
254
const dest = nextdir();
@@ -259,6 +259,23 @@ function nextdir(dirname) {
259
cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true }));
260
261
262
+// It allows cp copying symlinks in src to locations in dest with existing synlinks not pointing to a directory.
263
+{
264
+ const src = nextdir();
265
+ const dest = nextdir();
266
+ mkdirSync(src, mustNotMutateObjectDeep({ recursive: true }));
267
+ writeFileSync(`${src}/test.txt`, 'test');
268
+ symlinkSync(resolve(`${src}/test.txt`), join(src, 'link.txt'));
269
+ cp(src, dest, { recursive: true },
270
+ mustCall((err) => {
271
+ assert.strictEqual(err, null);
272
273
+ cp(src, dest, { recursive: true }, mustCall((err) => {
274
275
+ }));
276
277
+}
278
279
// It throws error if symlink in dest points to location in src.
280
281
0 commit comments