diff --git a/lib/internal/fs/copy/copy-sync.js b/lib/internal/fs/copy/copy-sync.js index 6090f886c4a44c..a84089d3ff1064 100644 --- a/lib/internal/fs/copy/copy-sync.js +++ b/lib/internal/fs/copy/copy-sync.js @@ -33,12 +33,10 @@ const { const fs = require('fs'); const { chmodSync, - closeSync, copyFileSync, existsSync, lstatSync, mkdirSync, - openSync, readdirSync, readlinkSync, statSync, diff --git a/lib/internal/fs/copy/copy.js b/lib/internal/fs/copy/copy.js index 2b25e8e5de0cb1..136132501e7d14 100644 --- a/lib/internal/fs/copy/copy.js +++ b/lib/internal/fs/copy/copy.js @@ -46,7 +46,6 @@ const { copyFile, lstat, mkdir, - open, readdir, readlink, stat, @@ -62,6 +61,7 @@ const { resolve, sep, } = require('path'); +const console = require('console'); async function copyFn(src, dest, opts) { // Warn about using preserveTimestamps on 32-bit node @@ -337,7 +337,9 @@ async function copyDir(src, dest, opts) { async function onLink(destStat, src, dest) { let resolvedSrc = await readlink(src); if (!isAbsolute(resolvedSrc)) { + console.info(`resolve src ${dirname(src)} to ${resolvedSrc}`); resolvedSrc = resolve(dirname(src), resolvedSrc); + console.info(`resolved src ${resolvedSrc}`); } if (!destStat) { return symlink(resolvedSrc, dest); @@ -355,7 +357,9 @@ async function onLink(destStat, src, dest) { throw err; } if (!isAbsolute(resolvedDest)) { + console.info(`resolve dest ${dirname(dest)} to ${resolvedDest}`); resolvedDest = resolve(dirname(dest), resolvedDest); + console.info(`resolved dest ${resolvedDest}`); } if (isSrcSubdir(resolvedSrc, resolvedDest)) { throw new ERR_FS_COPY_TO_SUBDIRECTORY({ @@ -371,6 +375,9 @@ async function onLink(destStat, src, dest) { // dest in this case would result in removing src contents // and therefore a broken symlink would be created. const srcStat = await stat(src); + console.info(`${src} is directory? ${srcStat.isDirectory()}`); + console.info(`dest/src ${resolvedDest} ${resolvedSrc}`); + console.info(`${isSrcSubdir(resolvedDest, resolvedSrc)}`); if (srcStat.isDirectory() && isSrcSubdir(resolvedDest, resolvedSrc)) { throw new ERR_FS_COPY_SYMLINK_TO_SUBDIRECTORY({ code: 'EINVAL', diff --git a/test/parallel/test-fs-copy.js b/test/parallel/test-fs-copy.js index 4b2b6e1b40f9c4..a47626ef2dd509 100644 --- a/test/parallel/test-fs-copy.js +++ b/test/parallel/test-fs-copy.js @@ -30,6 +30,19 @@ function nextdir() { // Callback implementation of copy. + +// It returns error if symlink in dest points to location in src. +{ + const src = dirname(require.resolve('../fixtures/copy/kitchen-sink')); + const dest = nextdir(); + mkdirSync(join(dest, 'a'), { recursive: true }); + symlinkSync(src, join(dest, 'a', 'c')); + copy(src, dest, common.mustCall((err) => { + assert.strictEqual(err.code, 'ERR_FS_COPY_SYMLINK_TO_SUBDIRECTORY'); + })); +} + +/* // It copies a nested folder structure with files, folders, symlinks. { const src = dirname(require.resolve('../fixtures/copy/kitchen-sink')); @@ -118,17 +131,6 @@ function nextdir() { })); } -// It returns error if symlink in dest points to location in src. -{ - const src = dirname(require.resolve('../fixtures/copy/kitchen-sink')); - const dest = nextdir(); - mkdirSync(join(dest, 'a'), { recursive: true }); - symlinkSync(src, join(dest, 'a', 'c')); - copy(src, dest, common.mustCall((err) => { - assert.strictEqual(err.code, 'ERR_FS_COPY_SYMLINK_TO_SUBDIRECTORY'); - })); -} - // It returns error if parent directory of symlink in dest points to src. { const src = nextdir(); @@ -285,7 +287,7 @@ if (!isWindows) { assertDirEquivalent(src, dest); } testCase(); -} +}*/ function assertDirEquivalent(dir1, dir2) { const dir1Entries = [];