From fe73a033d36774f725ce1cf142ce7925c183520d Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman Date: Tue, 25 Oct 2022 16:04:16 -0400 Subject: [PATCH] Remove unneeded and buggy stats check As per https://github.com/nodejs/node/pull/39372#discussion_r1001179295 Resolves https://github.com/jprichardson/node-fs-extra/issues/918 --- lib/copy/copy-sync.js | 2 +- lib/copy/copy.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/copy/copy-sync.js b/lib/copy/copy-sync.js index 551abe0c..e2801eed 100644 --- a/lib/copy/copy-sync.js +++ b/lib/copy/copy-sync.js @@ -154,7 +154,7 @@ function onLink (destStat, src, dest, opts) { // prevent copy if src is a subdir of dest since unlinking // dest in this case would result in removing src contents // and therefore a broken symlink would be created. - if (fs.statSync(dest).isDirectory() && stat.isSrcSubdir(resolvedDest, resolvedSrc)) { + if (stat.isSrcSubdir(resolvedDest, resolvedSrc)) { throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`) } return copyLink(resolvedSrc, dest) diff --git a/lib/copy/copy.js b/lib/copy/copy.js index 09d53dfd..9e2e62e7 100644 --- a/lib/copy/copy.js +++ b/lib/copy/copy.js @@ -216,7 +216,7 @@ function onLink (destStat, src, dest, opts, cb) { // do not copy if src is a subdir of dest since unlinking // dest in this case would result in removing src contents // and therefore a broken symlink would be created. - if (destStat.isDirectory() && stat.isSrcSubdir(resolvedDest, resolvedSrc)) { + if (stat.isSrcSubdir(resolvedDest, resolvedSrc)) { return cb(new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)) } return copyLink(resolvedSrc, dest, cb)