From 1a3205db942d92f0b8b5a306f6a0466ab2c5f8b7 Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman Date: Sat, 19 Nov 2022 13:09:05 -0500 Subject: [PATCH] Remove unneeded and buggy stats check (#976) 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 30e95222..8bc60119 100644 --- a/lib/copy/copy-sync.js +++ b/lib/copy/copy-sync.js @@ -146,7 +146,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 53423e0e..bc188fb6 100644 --- a/lib/copy/copy.js +++ b/lib/copy/copy.js @@ -219,7 +219,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)