Node-fs-extra: copySync throw error when directory has unreachable symlinks

Created on 24 Feb 2020  路  8Comments  路  Source: jprichardson/node-fs-extra


  • Operating System:
    mac
  • Node.js version:
    v12.14.0
  • fs-extra version:
    8.1.0

error line:
https://github.com/jprichardson/node-fs-extra/blob/master/lib/copy-sync/copy-sync.js#L121

function copyDirItem stat.checkPathsSync should be use fs.lstatSync when options:dereference is false

feature-copy

Most helpful comment

I've encounted this issue as well.

Online demo reproducing the issue: https://repl.it/repls/OvalCruelApplets

All 8 comments

quick fix
util/stat.js:getStatsSync

function getStatsSync (src, dest, opts = {}) {
  let srcStat, destStat
  const statSync = opts.dereference ? fs.statSync : fs.lstatSync
  if (nodeSupportsBigInt()) {
    srcStat = statSync(src, { bigint: true })
  } else {
    srcStat = statSync(src)
  }
  try {
    if (nodeSupportsBigInt()) {
      destStat = statSync(dest, { bigint: true })
    } else {
      destStat = statSync(dest)
    }
  } catch (err) {
    if (err.code === 'ENOENT') return { srcStat, destStat: null }
    throw err
  }


  return { srcStat, destStat }
}

@manidlou Can you take a look at this?

Sure thing!

@lljxx1 can you give us a reproducible test case please?

fundembp:alternatives fun$ ls -l
total 0
lrwxr-xr-x  1 fun  staff  31  2 24 09:57 phar -> /code/.fun/root/usr/bin/phar7.0
lrwxr-xr-x  1 fun  staff  47  2 24 09:57 phar.1.gz -> /code/.fun/root/usr/share/man/man1/phar7.0.1.gz
lrwxr-xr-x  1 fun  staff  36  2 24 09:57 phar.phar -> /code/.fun/root/usr/bin/phar.phar7.0
lrwxr-xr-x  1 fun  staff  52  2 24 09:57 phar.phar.1.gz -> /code/.fun/root/usr/share/man/man1/phar.phar7.0.1.gz
lrwxr-xr-x  1 fun  staff  30  2 24 09:57 php -> /code/.fun/root/usr/bin/php7.0
lrwxr-xr-x  1 fun  staff  34  2 24 09:57 php-cgi -> /code/.fun/root/usr/bin/php-cgi7.0
lrwxr-xr-x  1 fun  staff  38  2 24 09:57 php-cgi-bin -> /code/.fun/root/usr/lib/cgi-bin/php7.0
lrwxr-xr-x  1 fun  staff  50  2 24 09:57 php-cgi.1.gz -> /code/.fun/root/usr/share/man/man1/php-cgi7.0.1.gz
lrwxr-xr-x  1 fun  staff  46  2 24 09:57 php.1.gz -> /code/.fun/root/usr/share/man/man1/php7.0.1.gz

here is the example, the /code folder is not exists

I've encounted this issue as well.

Online demo reproducing the issue: https://repl.it/repls/OvalCruelApplets

As a quick workaround to anyone who also found this issue but doesn't want to patch node modules locally, https://www.npmjs.com/package/ncp seems to be a fine alternative for copy.

With that said, it seems the fix was just merged into v10, so hopefully this should be closed out soon! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

louwers picture louwers  路  4Comments

EsTharian picture EsTharian  路  3Comments

monolithed picture monolithed  路  5Comments

milesj picture milesj  路  7Comments

solutionstack picture solutionstack  路  3Comments