isaacs / rimraf

A `rm -rf` util for nodejs
ISC License
5.66k stars 252 forks source link

Symlink's real files is deleted in Windows #276

Closed jamkitGO closed 1 year ago

jamkitGO commented 1 year ago

What happen: I found many people will use this lib to delete the files node_modules , so am I, it's helpful. But I found that in Windows, it will delete the symlink (usually created by npm link) in node_modules. And What it actually do is deleted the real file (symlink's real file) too.

Maybe it's our fault to use rimraf in that way, but it's dangerous (my symlink's real repository is deleted, which is unpushed 😢 ).

Expected: Maybe give some warning?

isaacs commented 1 year ago

Weird. Does lstat say it's a directory rather than a symbolic link? Maybe should return to the "try unlink, rmdir on EISDIR"? That fails on sunos though, where it's sometimes possible to unlink a directory and then bad stuff happens.

jamkitGO commented 1 year ago

Yes, I test again to confirm that it's symbolic link, and its real file is deleted. Sorry that I am poor in OS, so I can't offer you a suggestion, I just find what happen. If you confirm that, the easy way is to write it into README.md so people can notice that.

isaacs commented 1 year ago

I haven't been able to reproduce this on Windows. Some additional details will be needed:

  1. What is the symbolic link filename that was passed to rimraf?
  2. What is the target of that symbolic link?
  3. What is the output of this command? node -p "st=require('fs').lstatSync(process.argv[2]);[st,st.isSymbolicLink()]" <symbolic link from step 1>
  4. What is the output of this command? ls -laF <symbolic link from step 1>
  5. What is the output of this command? node -p "require('fs').readlinkSync(process.argv[2])" <symbolic link from step 1>