watcher runs into infinite loop on circular symLinks within the file system #56

Closed
leiterschleife opened this Issue Oct 8, 2013 · 6 comments

Projects

None yet

5 participants

@leiterschleife

Test it by creating a symbolic link one or two levels up in the file system, watch any directory within the loop, see how it adds and adds directory after directory to the watched ones.

I would like to have an option whether to add directories recursively or not. My use case is to watch a specific directory, but no descendants of it.

As far as I can see, the problem lies with index.coffee form lines 165-169. An option to follow the directory recursively would be very nice.

@jagill
jagill commented Nov 7, 2013

It would also be nice if we could pass an option whether to follow symlinks or not.

@malandrew

This is easily solvable if chokidar uses fs.lstat instead of fs.stat.

Currently you can solve this with the following ignore function:

function symbolicLinkFilter(f, stat) {
    return fs.lstatSync(f).isSymbolicLink();
}

Is there a reason stat is used instead of lstat?

@paulmillr
Owner

feel free to open a pr with this as optional behaviour

@malandrew

I was thinking about that. Mikeal's watch works the same way as chokidar. I've been noodling on the implications of letting a user opt for lstat instead of stat. I would imagine that the best solution is more complicated than choosing lstat or stat. If you choose lstat instead of stat, then you can't really follow symlinks selectively unless you add some sort of way to tell chokidar to continue.

If you look at substack's findit, you'll see that it has an interesting approach to terminating walking of certain branches. It emits special events for each type (file, directory, or symlink). When it reaches a directory for example it passes a local stop() function that will terminate that branch if called.

Right now I think the best approach is to let people solve it via the snippet above, since switching to lstat could be a breaking change for some people who, intentionally or unintentionally, rely on the follow symlinks behavior.

Any thoughts?

@paulmillr
Owner

Right now I think the best approach is to let people solve it via the snippet above, since switching to lstat could be a breaking change for some people who, intentionally or unintentionally, rely on the follow symlinks behavior.

yes

@es128 es128 added the bug label Nov 19, 2014
@es128 es128 added a commit that referenced this issue Dec 3, 2014
@es128 es128 Add failing test for circular symlinks 1c24bcb
@es128 es128 added a commit that referenced this issue Dec 3, 2014
@es128 es128 Fix for circular symlinks on non-fsevents
Allows one level of nested following

gh-56
a16bb82
@es128
Collaborator
es128 commented Dec 3, 2014

Fixed in master branch

@es128 es128 closed this Dec 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment