Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copySync throw error when directory has unreachable symlinks #765

Closed
lljxx1 opened this issue Feb 24, 2020 · 8 comments
Closed

copySync throw error when directory has unreachable symlinks #765

lljxx1 opened this issue Feb 24, 2020 · 8 comments
Assignees
Milestone

Comments

@lljxx1
Copy link

@lljxx1 lljxx1 commented Feb 24, 2020

  • 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

@lljxx1
Copy link
Author

@lljxx1 lljxx1 commented Feb 24, 2020

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 }
}

@RyanZim
Copy link
Collaborator

@RyanZim RyanZim commented Feb 24, 2020

@manidlou Can you take a look at this?

@manidlou
Copy link
Collaborator

@manidlou manidlou commented Feb 25, 2020

Sure thing!

@manidlou
Copy link
Collaborator

@manidlou manidlou commented Feb 25, 2020

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

@lljxx1
Copy link
Author

@lljxx1 lljxx1 commented Feb 27, 2020

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

@oznu
Copy link

@oznu oznu commented Mar 7, 2020

I've encounted this issue as well.

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

@tomasreimers
Copy link

@tomasreimers tomasreimers commented Aug 20, 2020

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! :)

@RyanZim
Copy link
Collaborator

@RyanZim RyanZim commented Apr 1, 2021

Fixed in #779

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants