Skip to content

Commit

Permalink
Modifying stream caching strategy to store subdirs.
Browse files Browse the repository at this point in the history
Any directory found during caching should be stored in its own cache. Otherwise, the cache is permanently empty for any sub-directory under a watched path.
  • Loading branch information
ymendel committed Jun 30, 2008
1 parent 6400f24 commit 5da4969
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/fsevents/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ def update_last_event
when :mtime
@last_event = Time.now
when :cache
paths.each do |path|
cache_paths = paths.dup
cache_paths.each do |path|
dirs[path] = {}
Dir["#{path}/*"].each do |file|
dirs[path][file] = File::Stat.new(file)
stat = File::Stat.new(file)
dirs[path][file] = stat
cache_paths.push(file) if stat.directory?
end
end
end
Expand Down
24 changes: 23 additions & 1 deletion spec/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
before :each do
@stream.stubs(:mode).returns(:cache)
@files = Array.new(5) { |i| stub("file #{i+1}") }
@stats = Array.new(5) { |i| stub("file #{i+1} stat") }
@stats = Array.new(5) { |i| stub("file #{i+1} stat", :directory? => false) }

@files.zip(@stats).each do |file, stat|
File::Stat.stubs(:new).with(file).returns(stat)
Expand Down Expand Up @@ -492,6 +492,28 @@
end
@stream.update_last_event
end

it 'should see if there are any subdirectories' do
@stats.each { |stat| stat.expects(:directory?) }
@stream.update_last_event
end

it 'should cache subdirectories' do
subdir_path = '/sub/dir/path'
@files[3].stubs(:to_s).returns(subdir_path)
@stats[3].stubs(:directory?).returns(true)
Dir.expects(:[]).with("#{subdir_path}/*").returns([])
@stream.update_last_event
end

it 'should not add cached subdirectories to the watched paths' do
subdir_path = '/sub/dir/path'
@files[3].stubs(:to_s).returns(subdir_path)
@stats[3].stubs(:directory?).returns(true)
Dir.stubs(:[]).with("#{subdir_path}/*").returns([])
@stream.update_last_event
@stream.paths.should_not include(@files[3])
end
end
end

Expand Down

0 comments on commit 5da4969

Please sign in to comment.