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

Listening fails for symlinks pointing outside the listened directory #71

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

Listening fails for symlinks pointing outside the listened directory #71

nex3 opened this issue Nov 30, 2012 · 6 comments

Comments

@nex3
Copy link
Contributor

nex3 commented Nov 30, 2012

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
Copy link
Member

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

@thibaudgg
Copy link
Member

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

@thibaudgg
Copy link
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
Copy link
Contributor Author

nex3 commented Dec 3, 2012

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
Copy link
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
Copy link
Member

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

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

2 participants