Skip to content

Can't clean broken symbolic links #99

@duanyao

Description

@duanyao

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions