diff --git a/.crystal-version b/.crystal-version index 1cf0537..697f087 100644 --- a/.crystal-version +++ b/.crystal-version @@ -1 +1 @@ -0.19.0 +0.28.0 diff --git a/spec/watchbird/pattern_spec.cr b/spec/watchbird/pattern_spec.cr index d5b9fb5..f3c4b6f 100644 --- a/spec/watchbird/pattern_spec.cr +++ b/spec/watchbird/pattern_spec.cr @@ -3,12 +3,14 @@ require "../../src/watchbird/pattern" describe WatchBird::Pattern do it "should separate fixed path and glob pattern" do + Dir.cd("/") pat = WatchBird::Pattern.new("/tmp/*") pat.fixed.should eq "/tmp/" pat.pattern.should eq "/tmp/*" end it "should not separate non-glob pattern" do + Dir.cd("/") pat = WatchBird::Pattern.new("/tmp/") pat.fixed.should eq "/tmp/" end diff --git a/src/watchbird/notifier/inotify.cr b/src/watchbird/notifier/inotify.cr index 201d474..72d5fe3 100644 --- a/src/watchbird/notifier/inotify.cr +++ b/src/watchbird/notifier/inotify.cr @@ -1,4 +1,4 @@ -require "./event" +require "../event" lib LibInotify struct Event @@ -92,7 +92,7 @@ module WatchBird size = @io.read(buf.to_slice) raise "inotify read() returned 0!" if size == 0 rescue e : IO::Error - if e.message == "closed stream" + if e.message == "Closed stream" return else raise e diff --git a/src/watchbird/pattern.cr b/src/watchbird/pattern.cr index 95857bc..09fc69e 100644 --- a/src/watchbird/pattern.cr +++ b/src/watchbird/pattern.cr @@ -17,7 +17,7 @@ module WatchBird end end @fixed = fixed_path - if pat[-1] == File::SEPARATOR || @fixed.size < abs_path.size + if @fixed[-1] != File::SEPARATOR && (pat[-1] == File::SEPARATOR || @fixed.size < abs_path.size) @fixed += File::SEPARATOR end if @fixed.size < abs_path.size diff --git a/src/watchbird/watcher.cr b/src/watchbird/watcher.cr index d288f2c..870fdb6 100644 --- a/src/watchbird/watcher.cr +++ b/src/watchbird/watcher.cr @@ -57,16 +57,15 @@ module WatchBird private def register_to_notifeir(pattern) @notifier.register(pattern.fixed) - Dir.foreach(pattern.fixed) do |name| - unless name == "." || name == ".." - fullname = pattern.fixed - if fullname[-1] != File::SEPARATOR - fullname += File::SEPARATOR - end - fullname += name - if Dir.exists?(fullname) - @notifier.register(fullname) - end + Dir.each_child(pattern.fixed) do |name| + next if name == "." || name == ".." + fullname = pattern.fixed + if fullname[-1] != File::SEPARATOR + fullname += File::SEPARATOR + end + fullname += name + if Dir.exists?(fullname) + @notifier.register(fullname) end end end