file_monitoring 0.0.4 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/file_monitoring +4 -2
- data/lib/file_monitoring/daemon_win32.rb +29 -0
- data/lib/file_monitoring/file_monitoring.rb +11 -10
- data/lib/file_monitoring/monitor_path.rb +19 -10
- data/lib/file_monitoring/version.rb +5 -0
- data/lib/file_monitoring.rb +1 -8
- data/test/file_monitoring/file_monitoring_test/conf.yml +4 -0
- data/test/file_monitoring/file_monitoring_test/conf_win32.yml +5 -0
- data/test/file_monitoring/file_monitoring_test/log +56 -0
- data/test/file_monitoring/file_monitoring_test.rb +0 -0
- data/test/file_monitoring/monitor_path_test/dir1000/test_file.1000 +1000 -0
- data/test/file_monitoring/monitor_path_test/dir1000/test_file.1000.0 +1000 -0
- data/test/file_monitoring/monitor_path_test/dir1000/test_file.1000.1 +1000 -0
- data/test/file_monitoring/monitor_path_test/dir1500/test_file.1500 +1500 -0
- data/test/file_monitoring/monitor_path_test/dir1500/test_file.1500.0 +1500 -0
- data/test/file_monitoring/monitor_path_test/dir1500/test_file.1500.1 +1500 -0
- data/test/file_monitoring/monitor_path_test/test_file.500 +500 -0
- data/test/file_monitoring/monitor_path_test/test_file.500.0 +500 -0
- data/test/file_monitoring/monitor_path_test/test_file.500.1 +500 -0
- data/test/file_monitoring/monitor_path_test.rb +157 -0
- metadata +71 -10
@@ -0,0 +1,500 @@
|
|
1
|
+
0
|
2
|
+
1
|
3
|
+
2
|
4
|
+
3
|
5
|
+
4
|
6
|
+
5
|
7
|
+
6
|
8
|
+
7
|
9
|
+
8
|
10
|
+
9
|
11
|
+
10
|
12
|
+
11
|
13
|
+
12
|
14
|
+
13
|
15
|
+
14
|
16
|
+
15
|
17
|
+
16
|
18
|
+
17
|
19
|
+
18
|
20
|
+
19
|
21
|
+
20
|
22
|
+
21
|
23
|
+
22
|
24
|
+
23
|
25
|
+
24
|
26
|
+
25
|
27
|
+
26
|
28
|
+
27
|
29
|
+
28
|
30
|
+
29
|
31
|
+
30
|
32
|
+
31
|
33
|
+
32
|
34
|
+
33
|
35
|
+
34
|
36
|
+
35
|
37
|
+
36
|
38
|
+
37
|
39
|
+
38
|
40
|
+
39
|
41
|
+
40
|
42
|
+
41
|
43
|
+
42
|
44
|
+
43
|
45
|
+
44
|
46
|
+
45
|
47
|
+
46
|
48
|
+
47
|
49
|
+
48
|
50
|
+
49
|
51
|
+
50
|
52
|
+
51
|
53
|
+
52
|
54
|
+
53
|
55
|
+
54
|
56
|
+
55
|
57
|
+
56
|
58
|
+
57
|
59
|
+
58
|
60
|
+
59
|
61
|
+
60
|
62
|
+
61
|
63
|
+
62
|
64
|
+
63
|
65
|
+
64
|
66
|
+
65
|
67
|
+
66
|
68
|
+
67
|
69
|
+
68
|
70
|
+
69
|
71
|
+
70
|
72
|
+
71
|
73
|
+
72
|
74
|
+
73
|
75
|
+
74
|
76
|
+
75
|
77
|
+
76
|
78
|
+
77
|
79
|
+
78
|
80
|
+
79
|
81
|
+
80
|
82
|
+
81
|
83
|
+
82
|
84
|
+
83
|
85
|
+
84
|
86
|
+
85
|
87
|
+
86
|
88
|
+
87
|
89
|
+
88
|
90
|
+
89
|
91
|
+
90
|
92
|
+
91
|
93
|
+
92
|
94
|
+
93
|
95
|
+
94
|
96
|
+
95
|
97
|
+
96
|
98
|
+
97
|
99
|
+
98
|
100
|
+
99
|
101
|
+
100
|
102
|
+
101
|
103
|
+
102
|
104
|
+
103
|
105
|
+
104
|
106
|
+
105
|
107
|
+
106
|
108
|
+
107
|
109
|
+
108
|
110
|
+
109
|
111
|
+
110
|
112
|
+
111
|
113
|
+
112
|
114
|
+
113
|
115
|
+
114
|
116
|
+
115
|
117
|
+
116
|
118
|
+
117
|
119
|
+
118
|
120
|
+
119
|
121
|
+
120
|
122
|
+
121
|
123
|
+
122
|
124
|
+
123
|
125
|
+
124
|
126
|
+
125
|
127
|
+
126
|
128
|
+
127
|
129
|
+
128
|
130
|
+
129
|
131
|
+
130
|
132
|
+
131
|
133
|
+
132
|
134
|
+
133
|
135
|
+
134
|
136
|
+
135
|
137
|
+
136
|
138
|
+
137
|
139
|
+
138
|
140
|
+
139
|
141
|
+
140
|
142
|
+
141
|
143
|
+
142
|
144
|
+
143
|
145
|
+
144
|
146
|
+
145
|
147
|
+
146
|
148
|
+
147
|
149
|
+
148
|
150
|
+
149
|
151
|
+
150
|
152
|
+
151
|
153
|
+
152
|
154
|
+
153
|
155
|
+
154
|
156
|
+
155
|
157
|
+
156
|
158
|
+
157
|
159
|
+
158
|
160
|
+
159
|
161
|
+
160
|
162
|
+
161
|
163
|
+
162
|
164
|
+
163
|
165
|
+
164
|
166
|
+
165
|
167
|
+
166
|
168
|
+
167
|
169
|
+
168
|
170
|
+
169
|
171
|
+
170
|
172
|
+
171
|
173
|
+
172
|
174
|
+
173
|
175
|
+
174
|
176
|
+
175
|
177
|
+
176
|
178
|
+
177
|
179
|
+
178
|
180
|
+
179
|
181
|
+
180
|
182
|
+
181
|
183
|
+
182
|
184
|
+
183
|
185
|
+
184
|
186
|
+
185
|
187
|
+
186
|
188
|
+
187
|
189
|
+
188
|
190
|
+
189
|
191
|
+
190
|
192
|
+
191
|
193
|
+
192
|
194
|
+
193
|
195
|
+
194
|
196
|
+
195
|
197
|
+
196
|
198
|
+
197
|
199
|
+
198
|
200
|
+
199
|
201
|
+
200
|
202
|
+
201
|
203
|
+
202
|
204
|
+
203
|
205
|
+
204
|
206
|
+
205
|
207
|
+
206
|
208
|
+
207
|
209
|
+
208
|
210
|
+
209
|
211
|
+
210
|
212
|
+
211
|
213
|
+
212
|
214
|
+
213
|
215
|
+
214
|
216
|
+
215
|
217
|
+
216
|
218
|
+
217
|
219
|
+
218
|
220
|
+
219
|
221
|
+
220
|
222
|
+
221
|
223
|
+
222
|
224
|
+
223
|
225
|
+
224
|
226
|
+
225
|
227
|
+
226
|
228
|
+
227
|
229
|
+
228
|
230
|
+
229
|
231
|
+
230
|
232
|
+
231
|
233
|
+
232
|
234
|
+
233
|
235
|
+
234
|
236
|
+
235
|
237
|
+
236
|
238
|
+
237
|
239
|
+
238
|
240
|
+
239
|
241
|
+
240
|
242
|
+
241
|
243
|
+
242
|
244
|
+
243
|
245
|
+
244
|
246
|
+
245
|
247
|
+
246
|
248
|
+
247
|
249
|
+
248
|
250
|
+
249
|
251
|
+
250
|
252
|
+
251
|
253
|
+
252
|
254
|
+
253
|
255
|
+
254
|
256
|
+
255
|
257
|
+
256
|
258
|
+
257
|
259
|
+
258
|
260
|
+
259
|
261
|
+
260
|
262
|
+
261
|
263
|
+
262
|
264
|
+
263
|
265
|
+
264
|
266
|
+
265
|
267
|
+
266
|
268
|
+
267
|
269
|
+
268
|
270
|
+
269
|
271
|
+
270
|
272
|
+
271
|
273
|
+
272
|
274
|
+
273
|
275
|
+
274
|
276
|
+
275
|
277
|
+
276
|
278
|
+
277
|
279
|
+
278
|
280
|
+
279
|
281
|
+
280
|
282
|
+
281
|
283
|
+
282
|
284
|
+
283
|
285
|
+
284
|
286
|
+
285
|
287
|
+
286
|
288
|
+
287
|
289
|
+
288
|
290
|
+
289
|
291
|
+
290
|
292
|
+
291
|
293
|
+
292
|
294
|
+
293
|
295
|
+
294
|
296
|
+
295
|
297
|
+
296
|
298
|
+
297
|
299
|
+
298
|
300
|
+
299
|
301
|
+
300
|
302
|
+
301
|
303
|
+
302
|
304
|
+
303
|
305
|
+
304
|
306
|
+
305
|
307
|
+
306
|
308
|
+
307
|
309
|
+
308
|
310
|
+
309
|
311
|
+
310
|
312
|
+
311
|
313
|
+
312
|
314
|
+
313
|
315
|
+
314
|
316
|
+
315
|
317
|
+
316
|
318
|
+
317
|
319
|
+
318
|
320
|
+
319
|
321
|
+
320
|
322
|
+
321
|
323
|
+
322
|
324
|
+
323
|
325
|
+
324
|
326
|
+
325
|
327
|
+
326
|
328
|
+
327
|
329
|
+
328
|
330
|
+
329
|
331
|
+
330
|
332
|
+
331
|
333
|
+
332
|
334
|
+
333
|
335
|
+
334
|
336
|
+
335
|
337
|
+
336
|
338
|
+
337
|
339
|
+
338
|
340
|
+
339
|
341
|
+
340
|
342
|
+
341
|
343
|
+
342
|
344
|
+
343
|
345
|
+
344
|
346
|
+
345
|
347
|
+
346
|
348
|
+
347
|
349
|
+
348
|
350
|
+
349
|
351
|
+
350
|
352
|
+
351
|
353
|
+
352
|
354
|
+
353
|
355
|
+
354
|
356
|
+
355
|
357
|
+
356
|
358
|
+
357
|
359
|
+
358
|
360
|
+
359
|
361
|
+
360
|
362
|
+
361
|
363
|
+
362
|
364
|
+
363
|
365
|
+
364
|
366
|
+
365
|
367
|
+
366
|
368
|
+
367
|
369
|
+
368
|
370
|
+
369
|
371
|
+
370
|
372
|
+
371
|
373
|
+
372
|
374
|
+
373
|
375
|
+
374
|
376
|
+
375
|
377
|
+
376
|
378
|
+
377
|
379
|
+
378
|
380
|
+
379
|
381
|
+
380
|
382
|
+
381
|
383
|
+
382
|
384
|
+
383
|
385
|
+
384
|
386
|
+
385
|
387
|
+
386
|
388
|
+
387
|
389
|
+
388
|
390
|
+
389
|
391
|
+
390
|
392
|
+
391
|
393
|
+
392
|
394
|
+
393
|
395
|
+
394
|
396
|
+
395
|
397
|
+
396
|
398
|
+
397
|
399
|
+
398
|
400
|
+
399
|
401
|
+
400
|
402
|
+
401
|
403
|
+
402
|
404
|
+
403
|
405
|
+
404
|
406
|
+
405
|
407
|
+
406
|
408
|
+
407
|
409
|
+
408
|
410
|
+
409
|
411
|
+
410
|
412
|
+
411
|
413
|
+
412
|
414
|
+
413
|
415
|
+
414
|
416
|
+
415
|
417
|
+
416
|
418
|
+
417
|
419
|
+
418
|
420
|
+
419
|
421
|
+
420
|
422
|
+
421
|
423
|
+
422
|
424
|
+
423
|
425
|
+
424
|
426
|
+
425
|
427
|
+
426
|
428
|
+
427
|
429
|
+
428
|
430
|
+
429
|
431
|
+
430
|
432
|
+
431
|
433
|
+
432
|
434
|
+
433
|
435
|
+
434
|
436
|
+
435
|
437
|
+
436
|
438
|
+
437
|
439
|
+
438
|
440
|
+
439
|
441
|
+
440
|
442
|
+
441
|
443
|
+
442
|
444
|
+
443
|
445
|
+
444
|
446
|
+
445
|
447
|
+
446
|
448
|
+
447
|
449
|
+
448
|
450
|
+
449
|
451
|
+
450
|
452
|
+
451
|
453
|
+
452
|
454
|
+
453
|
455
|
+
454
|
456
|
+
455
|
457
|
+
456
|
458
|
+
457
|
459
|
+
458
|
460
|
+
459
|
461
|
+
460
|
462
|
+
461
|
463
|
+
462
|
464
|
+
463
|
465
|
+
464
|
466
|
+
465
|
467
|
+
466
|
468
|
+
467
|
469
|
+
468
|
470
|
+
469
|
471
|
+
470
|
472
|
+
471
|
473
|
+
472
|
474
|
+
473
|
475
|
+
474
|
476
|
+
475
|
477
|
+
476
|
478
|
+
477
|
479
|
+
478
|
480
|
+
479
|
481
|
+
480
|
482
|
+
481
|
483
|
+
482
|
484
|
+
483
|
485
|
+
484
|
486
|
+
485
|
487
|
+
486
|
488
|
+
487
|
489
|
+
488
|
490
|
+
489
|
491
|
+
490
|
492
|
+
491
|
493
|
+
492
|
494
|
+
493
|
495
|
+
494
|
496
|
+
495
|
497
|
+
496
|
498
|
+
497
|
499
|
+
498
|
500
|
+
499
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require './lib/file_monitoring/monitor_path'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module BBFS
|
6
|
+
module FileMonitoring
|
7
|
+
module Test
|
8
|
+
class TestPathMonitor < ::Test::Unit::TestCase
|
9
|
+
# directory where tested files will be placed: __FILE__/time_modification_test
|
10
|
+
RESOURCES_DIR = File.expand_path(File.dirname(__FILE__) + '/path_monitor_test')
|
11
|
+
MOVE_DIR = '/dir1500' # directory that will be moved
|
12
|
+
MOVE_FILE = '/test_file.1000' # file that will be moved
|
13
|
+
MOVE_SRC_DIR = RESOURCES_DIR + '/dir1000' # directory where moved entities where placed
|
14
|
+
MOVE_DEST_DIR = RESOURCES_DIR # directory where moved entities will be placed
|
15
|
+
LOG_PATH = RESOURCES_DIR + '/../log.txt'
|
16
|
+
|
17
|
+
def setup
|
18
|
+
@sizes = [500, 1000, 1500]
|
19
|
+
@numb_of_copies = 2
|
20
|
+
@numb_entities = @sizes.size * (@numb_of_copies + 1) + @sizes.size
|
21
|
+
@test_file_name = 'test_file' # file name format: <test_file_name_prefix>.<size>[.serial_number_if_more_then_1]
|
22
|
+
@test_dir_name = 'dir'
|
23
|
+
::FileUtils.rm_rf(RESOURCES_DIR) if (File.exists?(RESOURCES_DIR))
|
24
|
+
|
25
|
+
# prepare files for testing
|
26
|
+
cur_dir = nil; # directory where currently files created in this iteration will be placed
|
27
|
+
|
28
|
+
@sizes.each do |size|
|
29
|
+
file_name = @test_file_name + '.' + size.to_s
|
30
|
+
|
31
|
+
if (cur_dir == nil)
|
32
|
+
cur_dir = String.new(RESOURCES_DIR)
|
33
|
+
else
|
34
|
+
cur_dir = cur_dir + "/#{@test_dir_name}" + size.to_s
|
35
|
+
end
|
36
|
+
Dir.mkdir(cur_dir) unless (File.exists?(cur_dir))
|
37
|
+
raise "Can't create writable working directory: #{cur_dir}" unless (File.exists?(cur_dir) and File.writable?(cur_dir))
|
38
|
+
|
39
|
+
file_path = cur_dir + '/' + file_name
|
40
|
+
File.open(file_path, 'w') do |file|
|
41
|
+
content = Array.new
|
42
|
+
size.times do |i|
|
43
|
+
content.push(sprintf('%5d ', i))
|
44
|
+
end
|
45
|
+
file.puts(content)
|
46
|
+
end
|
47
|
+
|
48
|
+
@numb_of_copies.times do |i|
|
49
|
+
::FileUtils.cp(file_path, "#{file_path}.#{i}")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_monitor
|
55
|
+
log = File.open(LOG_PATH, 'w+')
|
56
|
+
FileStat.set_log(log)
|
57
|
+
test_dir = DirStat.new(RESOURCES_DIR)
|
58
|
+
|
59
|
+
# Initial run of monitoring -> initializing DirStat object
|
60
|
+
# all found object will be set to NEW state
|
61
|
+
# no output to the log
|
62
|
+
test_dir.monitor
|
63
|
+
|
64
|
+
# all files will be set to UNCHANGED
|
65
|
+
log_prev_pos = log.pos
|
66
|
+
log_prev_line = log.lineno
|
67
|
+
test_dir.monitor
|
68
|
+
sleep(1) # to be sure that data was indeed written
|
69
|
+
log.pos= log_prev_pos
|
70
|
+
log.each_line do |line|
|
71
|
+
assert_equal(true, line.include?(FileStatEnum::UNCHANGED))
|
72
|
+
end
|
73
|
+
assert_equal(@numb_entities, log.lineno - log_prev_line) # checking that all entities were monitored
|
74
|
+
|
75
|
+
# move (equivalent to delete and create new) directory with including files to new location
|
76
|
+
::FileUtils.mv MOVE_SRC_DIR + MOVE_DIR, MOVE_DEST_DIR + MOVE_DIR
|
77
|
+
log_prev_pos = log.pos
|
78
|
+
log_prev_line = log.lineno
|
79
|
+
test_dir.monitor
|
80
|
+
sleep(1)
|
81
|
+
log.pos= log_prev_pos
|
82
|
+
log.each_line do |line|
|
83
|
+
if (line.include?(MOVE_SRC_DIR + MOVE_DIR))
|
84
|
+
assert_equal(true, line.include?(FileStatEnum::NON_EXISTING))
|
85
|
+
elsif (line.include?(MOVE_DEST_DIR + MOVE_DIR))
|
86
|
+
assert_equal(true, line.include?(FileStatEnum::NEW))
|
87
|
+
elsif (line.include?(MOVE_SRC_DIR) or line.include?(MOVE_DEST_DIR))
|
88
|
+
assert_not_equal(true, line.include?(FileStatEnum::UNCHANGED))
|
89
|
+
assert_equal(true, line.include?(FileStatEnum::CHANGED))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
# old and new containing directories: 2
|
93
|
+
# moved directory: 1
|
94
|
+
# deleted directory: 1
|
95
|
+
# moved files: @numb_of_copies + 1
|
96
|
+
assert_equal(5 + @numb_of_copies, log.lineno - log_prev_line) # checking that only MOVE_DIR_SRC, MOVE_DIR_DEST states were changed
|
97
|
+
|
98
|
+
# no changes:
|
99
|
+
# changed and new files moved to UNCHANGED
|
100
|
+
log_prev_pos = log.pos
|
101
|
+
log_prev_line = log.lineno
|
102
|
+
test_dir.monitor
|
103
|
+
sleep(1)
|
104
|
+
log.pos= log_prev_pos
|
105
|
+
log.each_line do |line|
|
106
|
+
assert_equal(true, line.include?(FileStatEnum::UNCHANGED))
|
107
|
+
end
|
108
|
+
# old and new containing directories: 2
|
109
|
+
# moved directory: 1
|
110
|
+
# moved files: @numb_of_copies + 1
|
111
|
+
assert_equal(4 + @numb_of_copies, log.lineno - log_prev_line)
|
112
|
+
|
113
|
+
# move (equivalent to delete and create new) file
|
114
|
+
log_prev_pos = log.pos
|
115
|
+
log_prev_line = log.lineno
|
116
|
+
::FileUtils.mv MOVE_SRC_DIR + MOVE_FILE, MOVE_DEST_DIR + MOVE_FILE
|
117
|
+
test_dir.monitor
|
118
|
+
sleep(1)
|
119
|
+
log.pos= log_prev_pos
|
120
|
+
log.each_line do |line|
|
121
|
+
if (line.include?MOVE_SRC_DIR + MOVE_FILE)
|
122
|
+
assert_equal(true, line.include?(FileStatEnum::NON_EXISTING))
|
123
|
+
elsif (line.include?MOVE_DEST_DIR + MOVE_FILE)
|
124
|
+
assert_equal(true, line.include?(FileStatEnum::NEW))
|
125
|
+
elsif (line.include?MOVE_SRC_DIR or line.include?MOVE_DEST_DIR)
|
126
|
+
assert_equal(true, line.include?(FileStatEnum::CHANGED))
|
127
|
+
end
|
128
|
+
end
|
129
|
+
# old and new containing directories: 2
|
130
|
+
# removed file: 1
|
131
|
+
# new file: 1
|
132
|
+
assert_equal(4, log.lineno - log_prev_line)
|
133
|
+
|
134
|
+
# all files were moved to UNCHANGED
|
135
|
+
test_dir.monitor
|
136
|
+
|
137
|
+
# check that all entities moved to stable
|
138
|
+
log_prev_pos = log.pos
|
139
|
+
log_prev_line = log.lineno
|
140
|
+
(test_dir.stable_state + 1).times do
|
141
|
+
test_dir.monitor
|
142
|
+
end
|
143
|
+
sleep(1)
|
144
|
+
log.pos= log_prev_pos
|
145
|
+
log.each_line do |line|
|
146
|
+
assert_equal(true, line.include?(FileStatEnum::STABLE))
|
147
|
+
end
|
148
|
+
assert_equal(@numb_entities, log.lineno - log_prev_line)
|
149
|
+
|
150
|
+
log.close
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|