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

Can't clean broken symbolic links #99

Open
duanyao opened this issue Apr 25, 2017 · 0 comments
Open

Can't clean broken symbolic links #99

duanyao opened this issue Apr 25, 2017 · 0 comments

Comments

@duanyao
Copy link

duanyao commented Apr 25, 2017

Steps to reproduce:

  • ln -s nonexists alink . nonexists is a non-existing file.
  • Create a clean task cleanBrokenLink: ['alink'] and run it. The output should be:
    Running "clean:cleanBrokenLink" (clean) task
    >> 1 path cleaned.
    
  • ls -l alink output: alink -> nonexists, showing that alink is not cleaned.

Note that broken symlinks could show up easily when cleaning a dir containing symlinks: if a link target was removed before the link is tried to remove, the link becomes broken.

Root cause: clean() in tasks/clean.js tests a filepath with grunt.file.exists() before trying to remove it, but grunt.file.exists() return false for a broken symbolic link (because of fs.exists() it calling), so clean() skips to remove it.

Possible solution: replace grunt.file.exists() with a fs.lstatSync() based solution, because it doesn't follow links. Additionally, grunt.file.isPathInCwd() also suffers from broken-symbolic-link problem.

antonionoca added a commit to antonionoca/grunt-contrib-clean that referenced this issue Oct 14, 2017
Using fs.unlink to remove symlink if exists.
Added test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant