Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Not stable against Dir.chdir; how to work around? #21

akerbos opened this Issue · 6 comments

2 participants


Consider this code:

require 'rubygems'
require 'listen'

callback = do |modified, added, removed|
  puts "m $#{modified.join(" ")}"
  puts "a $#{added.join(" ")}"
  puts "r $#{removed.join(" ")}"

@listener ='.').ignore('sub').change(&callback)      


Apparently, listen works with relative paths internally, which causes a) remove events for all files in the main directory after the chdir and b) events inside of sub to be reported after chdir (despite the ignore).

Using chdir with blocks, i.e.

Dir.chdir('sub') do 

does not help.

I suggest that listen should use total paths internally to be stable against this. If there are hard reasons against that, how can one circumvent the issue (short of not using chdir)?


A simple fix for your problem would be to pass Dir.pwd as an argument to It would indeed be better to convert the passed path into an absolute path to avoid this kind of problems in the future. Thanks for the report.


Could you try the fix and see it it helps with your case?


Now no change events seem to get through.


I just pushed a fix for the problem caused by the the previous one. Everything inside Listen now will be working with absolute paths to avoid the problems caused by changing the Dir.pwd of the process. Hopefully your example will work now as you would expect it to :)


Thanks! It works as expected in the simple case from above; when I edit files in the ignored subdirectory, those events are filtered.

However, when I modify a deeper file, say ./sub/sub2/test in above example, modified events are thrown.

Also, when I navigate into the ignored subdirectory's subdirectories with Nautilus, added events are thrown for those files that are viewed for the first time! Note that this does not happen for watched (sub)+directories. Weird?


Changes inside directories which are inside an ignored path does get reported, which should not happen! I'll investigate this and respond to you shortly. Thanks for reporting this weird bug :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.