Listening fails for symlinks pointing outside the listened directory #71

Closed
nex3 opened this Issue Nov 30, 2012 · 6 comments

2 participants

@nex3

The following code reproduces this for me on Ubuntu, using either the inotify or the polling backend:

require 'listen'
require 'fileutils'
require 'tmpdir'

Dir.mktmpdir do |tmp|
  puts "Creating dir"
  Dir.mkdir("#{tmp}/dir")

  puts "Creating linked"
  Dir.mkdir("#{tmp}/linked")

  puts "Linking dir/link -> linked"
  FileUtils.ln_s("../linked", "#{tmp}/dir/link")

  Thread.new do
    puts "Listening to dir"
    Listen.to("#{tmp}/dir") do |modified, added, removed|
      puts "Added: #{added.join(', ')}"
    end
  end

  sleep 1

  puts "Creating dir/file"
  File.open("#{tmp}/dir/file", 'w') {|f| f.puts("Hello, World!")}

  sleep 1

  puts "Creating linked/file"
  File.open("#{tmp}/linked/file", 'w') {|f| f.puts("Hello, World!")}
end
@thibaudgg
Guard member

Got the same results with rb-fsevent & polling on OS X. @Maher4Ever do you have any ideas to begin with?

@thibaudgg
Guard member

@nex3 could you submit a failing specs for this? It would be great, thanks in advance!

@thibaudgg
Guard member

Mmm after some thinking, I even not quite sure that your example could work because "#{tmp}/linked/file" is outside of the watched dir ("#{tmp}/dir") so the events will never be triggered. I think that a normal behavior (limitation!) and not an bug that can be resolved without listening to whole system directories.

@nex3

This could be handled by Listen itself by manually listening to symlinked directories that lie outside the primary directory. Otherwise clients that care about symlinks will all need to implement that behavior themselves.

I'd be happy to add a spec, but I'm not sure where such an integration-y test would go.

@thibaudgg
Guard member

Mmm, this would require a complete analyze on start to detect symlinked directories, it could have a bad performance impact. One another point to consider is new symlinked files/directories added after the start that would need to be listened as well.

I think it could theoretically work but sadly I wouldn't have much time this month to try an implementation, but if you want try it your self, I can tell you from where begin.

@thibaudgg
Guard member

btw, we should maybe merge this issue with #25.

@thibaudgg thibaudgg closed this Feb 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment