+23
-2
lines changedFilter options
+23
-2
lines changed Original file line number Diff line number Diff line change
@@ -54,6 +54,7 @@ const {
54
54
resolve,
55
55
sep,
56
56
} = require('path');
57
+
const fsBinding = internalBinding('fs');
57
58
58
59
async function cpFn(src, dest, opts) {
59
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)) {
345
346
resolvedDest = resolve(dirname(dest), resolvedDest);
346
347
}
347
-
if (isSrcSubdir(resolvedSrc, resolvedDest)) {
348
+
349
+
const srcIsDir = fsBinding.internalModuleStat(src) === 1;
350
+
351
+
if (srcIsDir && isSrcSubdir(resolvedSrc, resolvedDest)) {
348
352
throw new ERR_FS_CP_EINVAL({
349
353
message: `cannot copy ${resolvedSrc} to a subdirectory of self ` +
350
354
`${resolvedDest}`,
Original file line number Diff line number Diff line change
@@ -248,7 +248,7 @@ function nextdir(dirname) {
248
248
);
249
249
}
250
250
251
-
// It allows copying when is not a directory
251
+
// It allows cpSync copying symlinks in src to locations in dest with existing synlinks not pointing to a directory.
252
252
{
253
253
const src = nextdir();
254
254
const dest = nextdir();
@@ -259,6 +259,23 @@ function nextdir(dirname) {
259
259
cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true }));
260
260
}
261
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
+
assert.strictEqual(err, null);
275
+
}));
276
+
}));
277
+
}
278
+
262
279
// It throws error if symlink in dest points to location in src.
263
280
{
264
281
const src = nextdir();
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4