Closed ColinDKelley closed 3 years ago
@ms-ati brought up the risk that adding :modify
might lead to duplicate events.
That PR is all using stubs, so it doesn't disprove the possibility of duplicate events. I can try running an interactive test to see if that happens.
@ms-ati I ran this test on a Linux pod. It worked perfectly--no dups!
# cat listen-test.rb
require 'listen'
target = ARGV[0] or raise "no target given"
puts "listening to #{target}"
Listen.to(target) do |*args|
puts Hash[[:modified, :added, :removed].zip(args)].inspect
end.start
puts "sleeping..."
sleep
# bundle exec ruby listen-test.rb . &
[1] 489
listening to .
sleeping...
# touch a.dat
{:modified=>[], :added=>["/srv/app/listen-test/a.dat"], :removed=>[]}
# rm a.dat
{:modified=>[], :added=>[], :removed=>["/srv/app/listen-test/a.dat"]}
# touch b.dat
{:modified=>[], :added=>["/srv/app/listen-test/b.dat"], :removed=>[]}
# echo more >> b.dat
{:modified=>["/srv/app/listen-test/b.dat"], :added=>[], :removed=>[]}
# mv b.dat c.dat
{:modified=>[], :added=>["/srv/app/listen-test/c.dat"], :removed=>["/srv/app/listen-test/b.dat"]}
# kill %1
@ColinDKelley Awesome! Could you try editing a file and saving it, as opposed to running touch
, as well?
(that is -- not simply appending -- but editing and saving)
@ms-ati I ran that test on a Linux pod and it worked exactly as expected. I tried both editing an existing file, and a new one.
# bundle exec ruby listen-test.rb . &
[1] 151
listening to .
sleeping...
# touch a.txt
{:modified=>[], :added=>["/srv/app/listen-test/a.txt"], :removed=>[]}
# vi a.txt
(added a line and pressed ZZ to save and exit)
{:modified=>["/srv/app/listen-test/a.txt"], :added=>[], :removed=>[]}
# vi b.txt
(added a line and pressed ZZ to save and exit)
{:modified=>[], :added=>["/srv/app/listen-test/b.txt"], :removed=>[]}
# rm a.txt b.txt
{:modified=>[], :added=>[], :removed=>["/srv/app/listen-test/a.txt", "/srv/app/listen-test/b.txt"]}
BTW, I've added a variant of the above tests to the README since they seem helpful to understand how it works overall. https://github.com/guard/listen/pull/503
cc @ioquatix looks like this PR is pending your formal review in Github?
I'm going to merge and release as v3.3.0.pre.3 so we can get some burn-in time. I'm still interested in your review though, @ioquatix!
Fix for issue #450 .