file_monitoring 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/file_monitoring +3 -7
- data/lib/file_monitoring/file_monitoring.rb +59 -40
- data/lib/file_monitoring/monitor_path.rb +242 -224
- data/lib/file_monitoring.rb +19 -0
- metadata +19 -7
data/bin/file_monitoring
CHANGED
@@ -41,18 +41,14 @@ if ARGV.length > 1
|
|
41
41
|
conf_file_path = File.expand_path(ARGV[1])
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
daemon_suffix = '_' + ARGV[2]
|
47
|
-
end
|
48
|
-
|
49
|
-
puts "Config taken from:" + conf_file_path
|
44
|
+
puts "Taking config from:" + conf_file_path
|
45
|
+
YAML::load_file(conf_file_path) rescue abort("Can't load %s" % conf_file_path)
|
50
46
|
pid_dir = File.expand_path('~/.bbfs/run/')
|
51
47
|
FileUtils.mkdir_p(pid_dir)
|
52
48
|
puts "pid dir:" + pid_dir
|
53
49
|
|
54
50
|
Daemons.run_proc(
|
55
|
-
'file_monitoring'
|
51
|
+
'file_monitoring', # name of daemon
|
56
52
|
:dir_mode => :normal,
|
57
53
|
:dir => pid_dir, # directory where pid file will be stored
|
58
54
|
# :backtrace => true,
|
@@ -1,52 +1,71 @@
|
|
1
|
-
require './file_monitoring/monitor_path.rb'
|
2
1
|
require 'algorithms'
|
3
2
|
require 'fileutils'
|
3
|
+
require 'params'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
-
|
7
|
-
def monitor_files(config_path)
|
8
|
-
config_yml = YAML::load_file(config_path)
|
9
|
-
if config_yml
|
10
|
-
puts "Error loading config file, exiting."
|
11
|
-
return
|
12
|
-
end
|
6
|
+
require_relative 'monitor_path'
|
13
7
|
|
14
|
-
|
15
|
-
|
16
|
-
pq = Containers::PriorityQueue.new
|
17
|
-
conf_array.each { |elem|
|
18
|
-
priority = (Time.now + elem["scan_period"]).to_i
|
19
|
-
pq.push([priority, elem, DirStat.new(elem["path"], elem["stable_state"])], -priority)
|
20
|
-
}
|
21
|
-
|
22
|
-
log_path = File.expand_path("~/.bbfs/log/file_monitoring.log")
|
23
|
-
if config_yml.key?("log_path")
|
24
|
-
log_path = File.expand_path(config_yml["log_path"])
|
25
|
-
end
|
8
|
+
module BBFS
|
9
|
+
module FileMonitoring
|
26
10
|
|
27
|
-
|
28
|
-
|
29
|
-
log = File.open(log_path, 'w')
|
30
|
-
FileStat.set_log(log)
|
11
|
+
PARAMS.parameter('default_log_path', File.expand_path('~/.bbfs/log/file_monitoring.log'),
|
12
|
+
'Default path for log file.')
|
31
13
|
|
32
|
-
|
33
|
-
time, conf, dir_stat = pq.pop
|
34
|
-
#puts "time:" + time.to_s()
|
35
|
-
#puts "now:" + Time.now.to_i.to_s()
|
36
|
-
#puts conf
|
14
|
+
class FileMonitoring
|
37
15
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
16
|
+
def set_config_path(config_path)
|
17
|
+
@config_path = config_path
|
18
|
+
end
|
42
19
|
|
43
|
-
|
20
|
+
def set_event_queue(queue)
|
21
|
+
@event_queue = queue
|
22
|
+
end
|
44
23
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
24
|
+
def monitor_files
|
25
|
+
config_yml = YAML::load_file(@config_path)
|
26
|
+
|
27
|
+
conf_array = config_yml['paths']
|
28
|
+
|
29
|
+
pq = Containers::PriorityQueue.new
|
30
|
+
conf_array.each { |elem|
|
31
|
+
priority = (Time.now + elem['scan_period']).to_i
|
32
|
+
dir_stat = DirStat.new(elem['path'], elem['stable_state'])
|
33
|
+
dir_stat.set_event_queue(@event_queue) if @event_queue
|
34
|
+
pq.push([priority, elem, dir_stat], -priority)
|
35
|
+
}
|
36
|
+
|
37
|
+
log_path = PARAMS.default_log_path
|
38
|
+
if config_yml.key?('log_path')
|
39
|
+
log_path = File.expand_path(config_yml['log_path'])
|
40
|
+
end
|
41
|
+
|
42
|
+
puts 'Log path:' + log_path
|
43
|
+
FileUtils.mkdir_p(File.dirname(log_path))
|
44
|
+
log = File.open(log_path, 'w')
|
45
|
+
FileStat.set_log(log)
|
50
46
|
|
51
|
-
|
47
|
+
while true do
|
48
|
+
time, conf, dir_stat = pq.pop
|
49
|
+
#puts 'time:' + time.to_s()
|
50
|
+
#puts 'now:' + Time.now.to_i.to_s()
|
51
|
+
#puts conf
|
52
|
+
|
53
|
+
time_span = time - Time.now.to_i
|
54
|
+
if (time_span > 0)
|
55
|
+
sleep(time_span)
|
56
|
+
end
|
57
|
+
|
58
|
+
dir_stat.monitor
|
59
|
+
|
60
|
+
#puts conf['path']
|
61
|
+
#puts conf['scan_period']
|
62
|
+
priority = (Time.now + conf['scan_period']).to_i
|
63
|
+
pq.push([priority, conf, dir_stat], -priority)
|
64
|
+
end
|
65
|
+
|
66
|
+
log.close
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
52
71
|
end
|
@@ -1,265 +1,283 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
|
5
|
-
#
|
6
|
-
# * <tt>
|
7
|
-
# * <tt>
|
8
|
-
# * <tt>
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
class FileStat
|
19
|
-
attr_reader :cycles, :path, :stable_state, :state, :size, :modification_time
|
1
|
+
module BBFS
|
2
|
+
module FileMonitoring
|
3
|
+
# Path monitoring.
|
4
|
+
|
5
|
+
# Enum-like structure that includes possible filesystem entities (files/directories) states:
|
6
|
+
# * <tt>NON_EXISTING</tt> - Entity that was treated during previous run, but absent currently
|
7
|
+
# * <tt>NEW</tt> - Entity that was found and added to control during this run
|
8
|
+
# * <tt>CHANGED</tt> - State was changed between two checks
|
9
|
+
# * <tt>UNCHANGED</tt> - Opposite to CHANGED
|
10
|
+
# * <tt>STABLE</tt> - Entity is in the UNCHANGED state for a defined (by user) number of iterations
|
11
|
+
class FileStatEnum
|
12
|
+
NON_EXISTING = "NON_EXISTING"
|
13
|
+
NEW = "NEW"
|
14
|
+
CHANGED = "CHANGED"
|
15
|
+
UNCHANGED = "UNCHANGED"
|
16
|
+
STABLE = "STABLE"
|
17
|
+
end
|
20
18
|
|
21
|
-
|
19
|
+
# This class holds current state of file and methods to control and report changes
|
20
|
+
class FileStat
|
21
|
+
attr_reader :cycles, :path, :stable_state, :state, :size, :modification_time
|
22
22
|
|
23
|
-
|
23
|
+
DEFAULT_STABLE_STATE = 10
|
24
24
|
|
25
|
-
|
26
|
-
# ==== Arguments:
|
27
|
-
#
|
28
|
-
# * <tt>path</tt> - File location
|
29
|
-
# * <tt>stable_state</tt> - Number of iterations to move unchanged file to stable state
|
30
|
-
def initialize(path, stable_state = DEFAULT_STABLE_STATE)
|
31
|
-
@path ||= path
|
32
|
-
@size = nil
|
33
|
-
@modification_time = nil
|
34
|
-
@cycles = 0 # number of iterations from the last file modification
|
35
|
-
@state = FileStatEnum::NON_EXISTING
|
25
|
+
@@log = nil
|
36
26
|
|
37
|
-
|
38
|
-
|
27
|
+
# Initializes new file monitoring object
|
28
|
+
# ==== Arguments:
|
29
|
+
#
|
30
|
+
# * <tt>path</tt> - File location
|
31
|
+
# * <tt>stable_state</tt> - Number of iterations to move unchanged file to stable state
|
32
|
+
def initialize(path, stable_state = DEFAULT_STABLE_STATE)
|
33
|
+
@path ||= path
|
34
|
+
@size = nil
|
35
|
+
@modification_time = nil
|
36
|
+
@cycles = 0 # number of iterations from the last file modification
|
37
|
+
@state = FileStatEnum::NON_EXISTING
|
39
38
|
|
40
|
-
#
|
41
|
-
|
42
|
-
#
|
43
|
-
# * <tt>log</tt> - already opened ruby File object
|
44
|
-
def self.set_log (log)
|
45
|
-
@@log = log
|
46
|
-
end
|
39
|
+
@stable_state = stable_state # number of iteration to move unchanged file to stable state
|
40
|
+
end
|
47
41
|
|
48
|
-
|
49
|
-
|
50
|
-
def monitor
|
51
|
-
file_stats = File.lstat(@path) rescue nil
|
52
|
-
new_state = nil
|
53
|
-
if file_stats == nil
|
54
|
-
new_state = FileStatEnum::NON_EXISTING
|
55
|
-
@size = nil
|
56
|
-
@modification_time = nil
|
57
|
-
@cycles = 0
|
58
|
-
elsif @size == nil
|
59
|
-
new_state = FileStatEnum::NEW
|
60
|
-
@size = file_stats.size
|
61
|
-
@modification_time = file_stats.mtime.utc
|
62
|
-
@cycles = 0
|
63
|
-
elsif changed?(file_stats)
|
64
|
-
new_state = FileStatEnum::CHANGED
|
65
|
-
@size = file_stats.size
|
66
|
-
@modification_time = file_stats.mtime.utc
|
67
|
-
@cycles = 0
|
68
|
-
else
|
69
|
-
new_state = FileStatEnum::UNCHANGED
|
70
|
-
@cycles += 1
|
71
|
-
if @cycles >= @stable_state
|
72
|
-
new_state = FileStatEnum::STABLE
|
42
|
+
def set_output_queue event_queue
|
43
|
+
@event_queue
|
73
44
|
end
|
74
|
-
end
|
75
45
|
|
76
|
-
|
77
|
-
|
78
|
-
|
46
|
+
# Sets a log file to report changes
|
47
|
+
# ==== Arguments:
|
48
|
+
#
|
49
|
+
# * <tt>log</tt> - already opened ruby File object
|
50
|
+
def self.set_log (log)
|
51
|
+
@@log = log
|
52
|
+
end
|
79
53
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
54
|
+
# Checks whether file was changed from the last iteration.
|
55
|
+
# For files size and modification time are checked.
|
56
|
+
def monitor
|
57
|
+
file_stats = File.lstat(@path) rescue nil
|
58
|
+
new_state = nil
|
59
|
+
if file_stats == nil
|
60
|
+
new_state = FileStatEnum::NON_EXISTING
|
61
|
+
@size = nil
|
62
|
+
@modification_time = nil
|
63
|
+
@cycles = 0
|
64
|
+
elsif @size == nil
|
65
|
+
new_state = FileStatEnum::NEW
|
66
|
+
@size = file_stats.size
|
67
|
+
@modification_time = file_stats.mtime.utc
|
68
|
+
@cycles = 0
|
69
|
+
elsif changed?(file_stats)
|
70
|
+
new_state = FileStatEnum::CHANGED
|
71
|
+
@size = file_stats.size
|
72
|
+
@modification_time = file_stats.mtime.utc
|
73
|
+
@cycles = 0
|
74
|
+
else
|
75
|
+
new_state = FileStatEnum::UNCHANGED
|
76
|
+
@cycles += 1
|
77
|
+
if @cycles >= @stable_state
|
78
|
+
new_state = FileStatEnum::STABLE
|
79
|
+
end
|
80
|
+
end
|
84
81
|
|
85
|
-
|
86
|
-
|
87
|
-
if (@state != new_state or @state == FileStatEnum::CHANGED)
|
88
|
-
@state = new_state
|
89
|
-
if (@@log)
|
90
|
-
@@log.puts(cur_stat)
|
91
|
-
@@log.flush #Ruby1.9.3: note that this is Ruby internal buffering only; the OS may buffer the data as well
|
82
|
+
# The assignment
|
83
|
+
self.state= new_state
|
92
84
|
end
|
93
|
-
end
|
94
|
-
end
|
95
85
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
86
|
+
# Checks that stored file attributes are the same as file attributes taken from file system.
|
87
|
+
def changed?(file_stats)
|
88
|
+
not (file_stats.size == size and file_stats.mtime.utc == modification_time.utc)
|
89
|
+
end
|
100
90
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
91
|
+
def set_event_queue(queue)
|
92
|
+
@event_queue = queue
|
93
|
+
end
|
105
94
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
95
|
+
# Sets and writes to the log a new state.
|
96
|
+
def state= (new_state)
|
97
|
+
if (@state != new_state or @state == FileStatEnum::CHANGED)
|
98
|
+
@state = new_state
|
99
|
+
if (@@log)
|
100
|
+
@@log.puts(cur_stat)
|
101
|
+
@@log.flush #Ruby1.9.3: note that this is Ruby internal buffering only; the OS may buffer the data as well
|
102
|
+
end
|
103
|
+
if (@event_queue && !self.instance_of?(DirStat))
|
104
|
+
p "Writing to event queue [#{self.state}, #{self.path}]"
|
105
|
+
@event_queue.push([self.state, self.path])
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
113
109
|
|
114
|
-
#
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
#
|
119
|
-
# * <tt>path</tt> - File location
|
120
|
-
# * <tt>stable_state</tt> - Number of iterations to move unchanged directory to stable state
|
121
|
-
def initialize(path, stable_state = DEFAULT_STABLE_STATE)
|
122
|
-
super
|
123
|
-
@dirs = nil
|
124
|
-
@files = nil
|
125
|
-
end
|
110
|
+
# Checks whether path and state are the same as of the argument
|
111
|
+
def == (other)
|
112
|
+
@path == other.path and @stable_state == other.stable_state
|
113
|
+
end
|
126
114
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
115
|
+
# Returns path and state of the file with indentation
|
116
|
+
def to_s (indent = 0)
|
117
|
+
(" " * indent) + path.to_s + " : " + state.to_s
|
118
|
+
end
|
131
119
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
120
|
+
# Reports current state with identification.
|
121
|
+
# # This format used by log file.
|
122
|
+
def cur_stat
|
123
|
+
# TODO what output format have to be ?
|
124
|
+
Time.now.utc.to_s + " : " + self.state + " : " + self.path
|
125
|
+
end
|
126
|
+
end
|
136
127
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
128
|
+
# This class holds current state of directory and methods to control changes
|
129
|
+
class DirStat < FileStat
|
130
|
+
# Initializes new directory monitoring object
|
131
|
+
# ==== Arguments:
|
132
|
+
#
|
133
|
+
# * <tt>path</tt> - File location
|
134
|
+
# * <tt>stable_state</tt> - Number of iterations to move unchanged directory to stable state
|
135
|
+
def initialize(path, stable_state = DEFAULT_STABLE_STATE)
|
136
|
+
super
|
137
|
+
@dirs = nil
|
138
|
+
@files = nil
|
139
|
+
end
|
141
140
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
141
|
+
# Adds directory for monitoring.
|
142
|
+
def add_dir (dir)
|
143
|
+
@dirs[dir.path] = dir
|
144
|
+
end
|
146
145
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
146
|
+
# Adds file for monitoring.
|
147
|
+
def add_file (file)
|
148
|
+
@files[file.path] = file
|
149
|
+
end
|
151
150
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
151
|
+
# Removes directory from monitoring.
|
152
|
+
def rm_dir(dir)
|
153
|
+
@dirs.delete(dir.path)
|
154
|
+
end
|
156
155
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
res = super
|
162
|
-
@files.each_value do |file|
|
163
|
-
res += "\n" + file.to_s(child_ident)
|
164
|
-
end
|
165
|
-
@dirs.each_value do |dir|
|
166
|
-
res += "\n" + dir.to_s(child_ident)
|
167
|
-
end
|
168
|
-
res
|
169
|
-
end
|
156
|
+
# Removes file from monitoring.
|
157
|
+
def rm_file(file)
|
158
|
+
@files.delete(file.path)
|
159
|
+
end
|
170
160
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
was_changed = false
|
175
|
-
new_state = nil
|
176
|
-
self_stat = File.lstat(@path) rescue nil
|
177
|
-
if self_stat == nil
|
178
|
-
new_state = FileStatEnum::NON_EXISTING
|
179
|
-
@files = nil
|
180
|
-
@dirs = nil
|
181
|
-
@cycles = 0
|
182
|
-
elsif @files == nil
|
183
|
-
new_state = FileStatEnum::NEW
|
184
|
-
@files = Hash.new
|
185
|
-
@dirs = Hash.new
|
186
|
-
@cycles = 0
|
187
|
-
update_dir
|
188
|
-
elsif update_dir
|
189
|
-
new_state = FileStatEnum::CHANGED
|
190
|
-
@cycles = 0
|
191
|
-
else
|
192
|
-
new_state = FileStatEnum::UNCHANGED
|
193
|
-
@cycles += 1
|
194
|
-
if @cycles >= @stable_state
|
195
|
-
new_state = FileStatEnum::STABLE
|
161
|
+
# Checks that there is a sub-folder with a given path.
|
162
|
+
def has_dir?(path)
|
163
|
+
@dirs.has_key?(path)
|
196
164
|
end
|
197
|
-
end
|
198
165
|
|
199
|
-
|
200
|
-
|
201
|
-
|
166
|
+
# Checks that there is a file with a given path.
|
167
|
+
def has_file?(path)
|
168
|
+
@files.has_key?(path)
|
169
|
+
end
|
202
170
|
|
203
|
-
|
204
|
-
|
205
|
-
|
171
|
+
# Returns string with contains path and state of this directory as well as it's structure.
|
172
|
+
def to_s(indent = 0)
|
173
|
+
indent_increment = 2
|
174
|
+
child_indent = indent + indent_increment
|
175
|
+
res = super
|
176
|
+
@files.each_value do |file|
|
177
|
+
res += "\n" + file.to_s(child_ident)
|
178
|
+
end
|
179
|
+
@dirs.each_value do |dir|
|
180
|
+
res += "\n" + dir.to_s(child_ident)
|
181
|
+
end
|
182
|
+
res
|
183
|
+
end
|
206
184
|
|
207
|
-
|
208
|
-
|
209
|
-
|
185
|
+
# Checks that directory structure (i.e. files and directories located directly under this directory)
|
186
|
+
# wasn't changed since the last iteration.
|
187
|
+
def monitor
|
188
|
+
was_changed = false
|
189
|
+
new_state = nil
|
190
|
+
self_stat = File.lstat(@path) rescue nil
|
191
|
+
if self_stat == nil
|
192
|
+
new_state = FileStatEnum::NON_EXISTING
|
193
|
+
@files = nil
|
194
|
+
@dirs = nil
|
195
|
+
@cycles = 0
|
196
|
+
elsif @files == nil
|
197
|
+
new_state = FileStatEnum::NEW
|
198
|
+
@files = Hash.new
|
199
|
+
@dirs = Hash.new
|
200
|
+
@cycles = 0
|
201
|
+
update_dir
|
202
|
+
elsif update_dir
|
203
|
+
new_state = FileStatEnum::CHANGED
|
204
|
+
@cycles = 0
|
205
|
+
else
|
206
|
+
new_state = FileStatEnum::UNCHANGED
|
207
|
+
@cycles += 1
|
208
|
+
if @cycles >= @stable_state
|
209
|
+
new_state = FileStatEnum::STABLE
|
210
|
+
end
|
211
|
+
end
|
210
212
|
|
211
|
-
|
212
|
-
|
213
|
-
rm_file(file)
|
213
|
+
# The assignment
|
214
|
+
self.state= new_state
|
214
215
|
end
|
215
|
-
end
|
216
216
|
|
217
|
-
|
218
|
-
|
217
|
+
# Updates the files and directories hashes and globs the directory for changes.
|
218
|
+
def update_dir
|
219
|
+
was_changed = false
|
219
220
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
end
|
224
|
-
end
|
221
|
+
# monitor existing and absent files
|
222
|
+
@files.each_value do |file|
|
223
|
+
file.monitor
|
225
224
|
|
226
|
-
|
225
|
+
if file.state == FileStatEnum::NON_EXISTING
|
226
|
+
was_changed = true
|
227
|
+
rm_file(file)
|
228
|
+
end
|
229
|
+
end
|
227
230
|
|
228
|
-
|
229
|
-
|
231
|
+
@dirs.each_value do |dir|
|
232
|
+
dir.monitor
|
230
233
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
# add and monitor new files and directories
|
237
|
-
files.each do |file|
|
238
|
-
file_stat = File.lstat(file) rescue nil
|
239
|
-
if (file_stat.directory?)
|
240
|
-
unless (has_dir?(file)) # new directory
|
241
|
-
# change state only for existing directories
|
242
|
-
# newly added directories have to remain with NEW state
|
243
|
-
was_changed = true
|
244
|
-
ds = DirStat.new(file, self.stable_state)
|
245
|
-
ds.monitor
|
246
|
-
add_dir(ds)
|
234
|
+
if dir.state == FileStatEnum::NON_EXISTING
|
235
|
+
was_changed = true
|
236
|
+
rm_dir(dir)
|
237
|
+
end
|
247
238
|
end
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
239
|
+
|
240
|
+
was_changed = was_changed || glob_me
|
241
|
+
|
242
|
+
return was_changed
|
243
|
+
end
|
244
|
+
|
245
|
+
# Globs the directory for new files and directories
|
246
|
+
def glob_me
|
247
|
+
was_changed = false
|
248
|
+
files = Dir.glob(path + "/*")
|
249
|
+
|
250
|
+
# add and monitor new files and directories
|
251
|
+
files.each do |file|
|
252
|
+
file_stat = File.lstat(file) rescue nil
|
253
|
+
if (file_stat.directory?)
|
254
|
+
unless (has_dir?(file)) # new directory
|
255
|
+
# change state only for existing directories
|
256
|
+
# newly added directories have to remain with NEW state
|
257
|
+
was_changed = true
|
258
|
+
ds = DirStat.new(file, self.stable_state)
|
259
|
+
ds.set_event_queue(@event_queue) if @event_queue
|
260
|
+
ds.monitor
|
261
|
+
add_dir(ds)
|
262
|
+
end
|
263
|
+
else # it is a file
|
264
|
+
unless(has_file?(file)) # new file
|
265
|
+
# change state only for existing directories
|
266
|
+
# newly added directories have to remain with NEW state
|
267
|
+
was_changed = true
|
268
|
+
fs = FileStat.new(file, self.stable_state)
|
269
|
+
fs.set_event_queue(@event_queue) if @event_queue
|
270
|
+
fs.monitor
|
271
|
+
add_file(fs)
|
272
|
+
end
|
273
|
+
end
|
256
274
|
end
|
275
|
+
|
276
|
+
return was_changed
|
257
277
|
end
|
278
|
+
|
279
|
+
protected :add_dir, :add_file, :rm_dir, :rm_file, :update_dir, :glob_me
|
258
280
|
end
|
259
281
|
|
260
|
-
return was_changed
|
261
282
|
end
|
262
|
-
|
263
|
-
protected :add_dir, :add_file, :rm_dir, :rm_file, :update_dir, :glob_me
|
264
283
|
end
|
265
|
-
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'params'
|
2
|
+
|
3
|
+
require_relative 'file_monitoring/file_monitoring'
|
4
|
+
|
5
|
+
# TODO add description
|
6
|
+
module BBFS
|
7
|
+
module FileMonitoring
|
8
|
+
VERSION = "0.0.3"
|
9
|
+
|
10
|
+
PARAMS.parameter("config_path","~/.bbfs/etc/file_monitoring.yml",
|
11
|
+
"Configuration file for monitoring.")
|
12
|
+
|
13
|
+
# The main method. Loops on all paths each time span and monitors them.
|
14
|
+
def monitor_files
|
15
|
+
fm = FileMonitoring.new
|
16
|
+
fm.monitor_files
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_monitoring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-01 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: algorithms
|
16
|
-
requirement: &
|
16
|
+
requirement: &70205909596200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70205909596200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: daemons
|
27
|
-
requirement: &
|
27
|
+
requirement: &70205909785420 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,18 +32,30 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
|
35
|
+
version_requirements: *70205909785420
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: params
|
38
|
+
requirement: &70205909903360 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70205909903360
|
47
|
+
description: Deamon for monitoring file changes in set of patterns (blobs).
|
37
48
|
email: kolmanv@gmail.com
|
38
49
|
executables:
|
39
50
|
- file_monitoring
|
40
51
|
extensions: []
|
41
52
|
extra_rdoc_files: []
|
42
53
|
files:
|
54
|
+
- lib/file_monitoring.rb
|
43
55
|
- lib/file_monitoring/file_monitoring.rb
|
44
56
|
- lib/file_monitoring/monitor_path.rb
|
45
57
|
- bin/file_monitoring
|
46
|
-
homepage:
|
58
|
+
homepage: http://github.com/kolmanv/bbfs
|
47
59
|
licenses: []
|
48
60
|
post_install_message:
|
49
61
|
rdoc_options: []
|