fs: fix cpSync handle existing symlinks
PR-URL: https://github.com/nodejs/node/pull/58476 Fixes: https://github.com/nodejs/node/issues/58468 Reviewed-By: Dario Piotrowicz <dario.piotrowicz@gmail.com>
This commit is contained in:
parent
49679ddd98
commit
0e8ae91855
@ -196,7 +196,9 @@ function onLink(destStat, src, dest, verbatimSymlinks) {
|
||||
if (!isAbsolute(resolvedDest)) {
|
||||
resolvedDest = resolve(dirname(dest), resolvedDest);
|
||||
}
|
||||
if (isSrcSubdir(resolvedSrc, resolvedDest)) {
|
||||
const srcIsDir = fsBinding.internalModuleStat(src) === 1;
|
||||
|
||||
if (srcIsDir && isSrcSubdir(resolvedSrc, resolvedDest)) {
|
||||
throw new ERR_FS_CP_EINVAL({
|
||||
message: `cannot copy ${resolvedSrc} to a subdirectory of self ` +
|
||||
`${resolvedDest}`,
|
||||
|
@ -15,7 +15,7 @@ const {
|
||||
writeFileSync,
|
||||
} = fs;
|
||||
import net from 'net';
|
||||
import { join } from 'path';
|
||||
import { join, resolve } from 'path';
|
||||
import { pathToFileURL } from 'url';
|
||||
import { setTimeout } from 'timers/promises';
|
||||
|
||||
@ -248,6 +248,17 @@ function nextdir(dirname) {
|
||||
);
|
||||
}
|
||||
|
||||
// It allows copying when is not a directory
|
||||
{
|
||||
const src = nextdir();
|
||||
const dest = nextdir();
|
||||
mkdirSync(src, mustNotMutateObjectDeep({ recursive: true }));
|
||||
writeFileSync(`${src}/test.txt`, 'test');
|
||||
symlinkSync(resolve(`${src}/test.txt`), join(src, 'link.txt'));
|
||||
cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true }));
|
||||
cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true }));
|
||||
}
|
||||
|
||||
// It throws error if symlink in dest points to location in src.
|
||||
{
|
||||
const src = nextdir();
|
||||
|
Loading…
x
Reference in New Issue
Block a user