filewatch 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,6 +33,7 @@ module FileWatch
33
33
  :stat_interval => 1,
34
34
  :discover_interval => 5,
35
35
  :exclude => [],
36
+ :start_new_files_at => :end
36
37
  }.merge(opts)
37
38
  if !@opts.include?(:sincedb_path)
38
39
  @opts[:sincedb_path] = File.join(ENV["HOME"], ".sincedb") if ENV.include?("HOME")
@@ -127,9 +128,17 @@ module FileWatch
127
128
  @sincedb[inode] = 0
128
129
  end
129
130
  elsif event == :create_initial && @files[path]
130
- @logger.debug("#{path}: initial create, no sincedb, seeking to end #{stat.size}")
131
- @files[path].sysseek(stat.size, IO::SEEK_SET)
132
- @sincedb[inode] = stat.size
131
+ # TODO(sissel): Allow starting at beginning of the file.
132
+ if @opts[:start_new_files_at] == :beginning
133
+ @logger.debug("#{path}: initial create, no sincedb, seeking to beginning of file")
134
+ @files[path].sysseek(0, IO::SEEK_SET)
135
+ @sincedb[inode] = 0
136
+ else
137
+ # seek to end
138
+ @logger.debug("#{path}: initial create, no sincedb, seeking to end #{stat.size}")
139
+ @files[path].sysseek(stat.size, IO::SEEK_SET)
140
+ @sincedb[inode] = stat.size
141
+ end
133
142
  else
134
143
  @logger.debug("#{path}: staying at position 0, no sincedb")
135
144
  end
@@ -112,7 +112,13 @@ module FileWatch
112
112
 
113
113
  private
114
114
  def _discover_file(path, initial=false)
115
- Dir.glob(path).each do |file|
115
+ globbed_dirs = Dir.glob(path)
116
+ @logger.debug("_discover_file_glob: #{path}: glob is: #{globbed_dirs}")
117
+ if globbed_dirs.empty? && File.file?(path)
118
+ globbed_dirs = [path]
119
+ @logger.debug("_discover_file_glob: #{path}: glob is: #{globbed_dirs} because glob did not work")
120
+ end
121
+ globbed_dirs.each do |file|
116
122
  next if @files.member?(file)
117
123
  next unless File.file?(file)
118
124
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filewatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-21 00:00:00.000000000 Z
13
+ date: 2012-09-16 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Watch files and directories in ruby. Also supports tailing and glob file
16
16
  patterns.
@@ -22,31 +22,31 @@ executables:
22
22
  extensions: []
23
23
  extra_rdoc_files: []
24
24
  files:
25
+ - lib/filewatch/watch.rb
25
26
  - lib/filewatch/tail.rb
26
27
  - lib/filewatch/buftok.rb
27
- - lib/filewatch/watch.rb
28
- - test/globtail/test9.data
29
- - test/globtail/test10.sh
30
- - test/globtail/test3.sh
31
- - test/globtail/test8.sh
32
- - test/globtail/test6.sh
33
- - test/globtail/test4.data
34
- - test/globtail/framework.sh
35
- - test/globtail/Makefile
28
+ - test/globtail/test4.sh
29
+ - test/globtail/test10.data
36
30
  - test/globtail/test5.data
37
- - test/globtail/test6.data
31
+ - test/globtail/Makefile
32
+ - test/globtail/test9.sh
33
+ - test/globtail/test7.sh
34
+ - test/globtail/test4.data
35
+ - test/globtail/test8.sh
36
+ - test/globtail/test10.sh
38
37
  - test/globtail/test7.data
39
38
  - test/globtail/test2.data
40
- - test/globtail/test5.sh
41
- - test/globtail/test10.data
42
- - test/globtail/test8.data
39
+ - test/globtail/test3.sh
40
+ - test/globtail/test6.data
43
41
  - test/globtail/test1.sh
44
- - test/globtail/test4.sh
45
- - test/globtail/test3.data
46
42
  - test/globtail/test1.data
47
- - test/globtail/test7.sh
43
+ - test/globtail/test8.data
44
+ - test/globtail/framework.sh
48
45
  - test/globtail/test2.sh
49
- - test/globtail/test9.sh
46
+ - test/globtail/test3.data
47
+ - test/globtail/test9.data
48
+ - test/globtail/test5.sh
49
+ - test/globtail/test6.sh
50
50
  - bin/globtail
51
51
  homepage: https://github.com/jordansissel/ruby-filewatch
52
52
  licenses: []