Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .crystal-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.19.0
0.28.0
2 changes: 2 additions & 0 deletions spec/watchbird/pattern_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/watchbird/notifier/inotify.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "./event"
require "../event"

lib LibInotify
struct Event
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/watchbird/pattern.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions src/watchbird/watcher.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down