content_server 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/backup_server +3 -10
- data/bin/content_server +3 -10
- data/bin/testing_memory +3 -11
- data/bin/testing_server +3 -10
- data/lib/content_data/content_data.rb +9 -16
- data/lib/content_server/backup_server.rb +10 -9
- data/lib/content_server/content_receiver.rb +6 -6
- data/lib/content_server/content_server.rb +10 -10
- data/lib/content_server/file_streamer.rb +15 -13
- data/lib/content_server/queue_copy.rb +25 -23
- data/lib/content_server/queue_indexer.rb +11 -23
- data/lib/content_server/remote_content.rb +6 -6
- data/lib/content_server/server.rb +8 -7
- data/lib/content_server/version.rb +1 -1
- data/lib/file_copy/copy.rb +10 -9
- data/lib/file_monitoring/file_monitoring.rb +51 -18
- data/lib/file_monitoring/monitor_path.rb +68 -33
- data/lib/log.rb +40 -4
- data/lib/networking/tcp.rb +15 -15
- data/lib/params.rb +3 -9
- metadata +2 -2
@@ -21,47 +21,35 @@ module ContentServer
|
|
21
21
|
# Start indexing on demand and write changes to queue
|
22
22
|
thread = Thread.new do
|
23
23
|
while true do
|
24
|
-
Log.debug1 'Waiting on index input queue.'
|
25
24
|
(state, is_dir, path, mtime, size) = @input_queue.pop
|
26
25
|
$process_vars.set('monitor to index queue size', @input_queue.size)
|
27
|
-
Log.debug1
|
26
|
+
Log.debug1("index event: state:%s dir?%s path:%s time:%s size:%s ",
|
27
|
+
state, is_dir, path, mtime, size)
|
28
28
|
if state == FileMonitoring::FileStatEnum::STABLE && !is_dir
|
29
29
|
# Calculating checksum
|
30
|
-
|
30
|
+
checksum = calc_SHA1(path)
|
31
|
+
$process_vars.inc('indexed_files')
|
32
|
+
$indexed_file_count += 1
|
33
|
+
Log.debug1("Index checksum:%s Adding index to content data. put in queue for dynamic update.",
|
34
|
+
checksum)
|
31
35
|
$local_content_data_lock.synchronize{
|
32
|
-
|
36
|
+
$local_content_data.add_instance(checksum, size, Params['local_server_name'], path, mtime)
|
33
37
|
}
|
34
|
-
Log.debug1("instance !#{instance_stats}! mtime: #{mtime.to_i}, size: #{size}")
|
35
|
-
if instance_stats.nil? || mtime.to_i != instance_stats[1] || size != instance_stats[0]
|
36
|
-
Log.debug1 "Indexing file:'#{path}'."
|
37
|
-
checksum = calc_SHA1(path)
|
38
|
-
$process_vars.inc('indexed_files')
|
39
|
-
$indexed_file_count += 1
|
40
|
-
Log.debug1("Index info:checksum:#{checksum} size:#{size} time:#{mtime.to_i}")
|
41
|
-
Log.debug1('Adding index to content data. put in queue for dynamic update.')
|
42
|
-
$local_content_data_lock.synchronize{
|
43
|
-
$local_content_data.add_instance(checksum, size, Params['local_server_name'], path, mtime.to_i)
|
44
|
-
}
|
45
|
-
else
|
46
|
-
Log.info("Skip file #{path} indexing (shallow check passed)")
|
47
|
-
end
|
48
38
|
elsif ((state == FileMonitoring::FileStatEnum::NON_EXISTING ||
|
49
39
|
state == FileMonitoring::FileStatEnum::CHANGED) && !is_dir)
|
50
|
-
Log.debug2("NonExisting/Changed (file): #{path}")
|
51
40
|
# Remove file but only when non-existing.
|
52
|
-
Log.debug1("File to remove:
|
41
|
+
Log.debug1("File to remove: %s", path)
|
53
42
|
$local_content_data_lock.synchronize{
|
54
43
|
$local_content_data.remove_instance(Params['local_server_name'], path)
|
55
44
|
}
|
56
45
|
elsif state == FileMonitoring::FileStatEnum::NON_EXISTING && is_dir
|
57
|
-
Log.debug2("NonExisting/Changed (dir): #{path}")
|
58
46
|
# Remove directory but only when non-existing.
|
59
|
-
Log.debug1("Directory to remove:
|
47
|
+
Log.debug1("Directory to remove: %s", path)
|
60
48
|
$local_content_data_lock.synchronize{
|
61
49
|
$local_content_data.remove_directory(Params['local_server_name'], path)
|
62
50
|
}
|
63
51
|
else
|
64
|
-
Log.debug1("This case should not be handled:
|
52
|
+
Log.debug1("This case should not be handled: %s, %s, %s", state, is_dir, path)
|
65
53
|
end
|
66
54
|
end # while true do
|
67
55
|
end # Thread.new do
|
@@ -27,7 +27,8 @@ module ContentServer
|
|
27
27
|
@last_content_data_id = nil
|
28
28
|
@content_server_content_data_path = File.join(local_backup_folder, 'remote',
|
29
29
|
host + '_' + port.to_s)
|
30
|
-
Log.debug3("Initialized RemoteContentClient: host
|
30
|
+
Log.debug3("Initialized RemoteContentClient: host:%s port:%s local_backup_folder:%s",
|
31
|
+
host, port, local_backup_folder)
|
31
32
|
end
|
32
33
|
|
33
34
|
# Receives content data, and writes it to file
|
@@ -47,7 +48,7 @@ module ContentServer
|
|
47
48
|
$remote_content_data.to_file(path)
|
48
49
|
@last_content_data_id = message.unique_id # save last content data ID
|
49
50
|
}
|
50
|
-
Log.debug1("Written content data to file
|
51
|
+
Log.debug1("Written content data to file:%s.", path)
|
51
52
|
else
|
52
53
|
Log.debug1("No need to write remote content data, it has not changed.")
|
53
54
|
end
|
@@ -59,14 +60,13 @@ module ContentServer
|
|
59
60
|
threads = []
|
60
61
|
threads << @remote_tcp.tcp_thread if @remote_tcp != nil
|
61
62
|
threads << Thread.new do
|
62
|
-
Log.debug1("New thread.")
|
63
63
|
loop do
|
64
64
|
# if need content data
|
65
65
|
sleep_time_span = Params['remote_content_save_timeout']
|
66
66
|
if @last_fetch_timestamp
|
67
67
|
sleep_time_span = Time.now.to_i - @last_fetch_timestamp
|
68
68
|
end
|
69
|
-
Log.debug1("sleep_time_span:
|
69
|
+
Log.debug1("sleep_time_span: %s", sleep_time_span)
|
70
70
|
if sleep_time_span >= Params['remote_content_save_timeout']
|
71
71
|
# Send ping!
|
72
72
|
@remote_tcp.send_obj(nil)
|
@@ -85,7 +85,7 @@ module ContentServer
|
|
85
85
|
# initializes class variables
|
86
86
|
def initialize(port)
|
87
87
|
@tcp_server = Networking::TCPServer.new(port, method(:content_requested))
|
88
|
-
Log.debug3("initialize RemoteContentServer on port
|
88
|
+
Log.debug3("initialize RemoteContentServer on port:%s", port)
|
89
89
|
end
|
90
90
|
|
91
91
|
# content_requested
|
@@ -95,7 +95,7 @@ module ContentServer
|
|
95
95
|
# Send response.
|
96
96
|
Log.info("Content server received content data request")
|
97
97
|
$local_content_data_lock.synchronize{
|
98
|
-
Log.debug1("Sending content data
|
98
|
+
Log.debug1("Sending content data:%s", $local_content_data)
|
99
99
|
@tcp_server.send_obj($local_content_data)
|
100
100
|
}
|
101
101
|
Log.info('Content server sent content data')
|
@@ -42,12 +42,13 @@ module ContentServer
|
|
42
42
|
"Backtrace:\n#{exception.backtrace.join("\n")}"
|
43
43
|
puts(message)
|
44
44
|
|
45
|
+
# Block force write to file resolving Issue 217 https://github.com/bbfsdev/bbfs/issues/217
|
45
46
|
# force write content data to file
|
46
|
-
if $local_content_data
|
47
|
-
|
48
|
-
|
49
|
-
File.rename($tmp_content_data_file, Params['local_content_data_path'])
|
50
|
-
end
|
47
|
+
#if $local_content_data
|
48
|
+
# puts("\nForce writing local content data to #{Params['local_content_data_path']}.")
|
49
|
+
#$local_content_data.to_file($tmp_content_data_file)
|
50
|
+
#File.rename($tmp_content_data_file, Params['local_content_data_path'])
|
51
|
+
#end
|
51
52
|
|
52
53
|
#Write exception message to log and mail(if enabled)
|
53
54
|
Log.error(message)
|
@@ -83,9 +84,9 @@ module ContentServer
|
|
83
84
|
report += "Type:#{type} raised in:#{diff} \n"
|
84
85
|
objects_counters[type] = current_objects_counters[type]
|
85
86
|
}
|
86
|
-
Log.info("MEM REPORT
|
87
|
+
Log.info("MEM REPORT:\n%s\n", report)
|
87
88
|
end
|
88
89
|
end
|
89
90
|
|
90
91
|
module_function :init_globals, :handle_program_termination, :monitor_general_process_vars
|
91
|
-
end
|
92
|
+
end
|
data/lib/file_copy/copy.rb
CHANGED
@@ -13,7 +13,8 @@ module FileCopy
|
|
13
13
|
password = (password and password.length > 0) ? password : nil
|
14
14
|
port = 22 # 22 is a standart SSH port
|
15
15
|
raise "Undefined server" unless server
|
16
|
-
Log.debug1
|
16
|
+
Log.debug1("Trying to connect(ssh): %s, %s, %s, %s.",
|
17
|
+
username, password, server, port)
|
17
18
|
if (username and password)
|
18
19
|
Net::SSH.start(server, username,
|
19
20
|
:password => password,
|
@@ -22,7 +23,7 @@ module FileCopy
|
|
22
23
|
Net::SSH.start(server, username,
|
23
24
|
:port => port)
|
24
25
|
else
|
25
|
-
raise
|
26
|
+
raise("Undefined username")
|
26
27
|
end
|
27
28
|
end
|
28
29
|
module_function :ssh_connect
|
@@ -36,11 +37,11 @@ module FileCopy
|
|
36
37
|
uploads = files_map.map { |from,to|
|
37
38
|
remote_dir = File.dirname(to)
|
38
39
|
sftp_mkdir_recursive(sftp, File.dirname(to))
|
39
|
-
Log.debug1
|
40
|
+
Log.debug1("Copying %s to %s",from, to)
|
40
41
|
sftp.upload(from, to)
|
41
42
|
}
|
42
43
|
uploads.each { |u| u.wait }
|
43
|
-
Log.debug1
|
44
|
+
Log.debug1("Done.")
|
44
45
|
end # ssh.sftp.connect
|
45
46
|
end # def initialize
|
46
47
|
module_function :sftp_copy
|
@@ -48,17 +49,17 @@ module FileCopy
|
|
48
49
|
def sftp_mkdir_recursive(sftp, path)
|
49
50
|
dir_stat = nil
|
50
51
|
begin
|
51
|
-
Log.debug1
|
52
|
+
Log.debug1("Stat remote dir: %s.", path)
|
52
53
|
dir_stat = sftp.stat!(path).directory?
|
53
|
-
Log.debug1
|
54
|
+
Log.debug1("Stat result %s.", dir_stat)
|
54
55
|
rescue Net::SFTP::StatusException
|
55
56
|
end
|
56
57
|
if !dir_stat
|
57
|
-
Log.debug1
|
58
|
+
Log.debug1("Directory does not exists: %s.", path)
|
58
59
|
sftp_mkdir_recursive sftp, File.dirname(path)
|
59
|
-
Log.debug1
|
60
|
+
Log.debug1("Making dir %s.", path)
|
60
61
|
response = sftp.mkdir!(path)
|
61
|
-
Log.debug1
|
62
|
+
Log.debug1("Making dir ok:%s.", response.ok?)
|
62
63
|
end
|
63
64
|
end
|
64
65
|
module_function :sftp_mkdir_recursive
|
@@ -9,19 +9,6 @@ module FileMonitoring
|
|
9
9
|
# Manages file monitoring of number of file system locations
|
10
10
|
class FileMonitoring
|
11
11
|
|
12
|
-
def initialize ()
|
13
|
-
@content_data_cache = Set.new
|
14
|
-
$local_content_data_lock.synchronize {
|
15
|
-
$local_content_data.each_instance(){
|
16
|
-
|_, _, _, _, _, file_path|
|
17
|
-
# save files to cache
|
18
|
-
Log.info("File in cache: #{file_path.clone}")
|
19
|
-
@content_data_cache.add(file_path.clone)
|
20
|
-
}
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
12
|
# Set event queue used for communication between different proceses.
|
26
13
|
# @param queue [Queue]
|
27
14
|
def set_event_queue(queue)
|
@@ -41,16 +28,60 @@ module FileMonitoring
|
|
41
28
|
# that provides path and file monitoring configuration data
|
42
29
|
def monitor_files
|
43
30
|
conf_array = Params['monitoring_paths']
|
31
|
+
|
32
|
+
# create root dirs of monitoring
|
33
|
+
dir_stat_array = []
|
34
|
+
conf_array.each { |elem|
|
35
|
+
dir_stat = DirStat.new(File.expand_path(elem['path']), elem['stable_state'])
|
36
|
+
dir_stat.set_event_queue(@event_queue) if @event_queue
|
37
|
+
dir_stat_array.push(dir_stat)
|
38
|
+
}
|
39
|
+
|
40
|
+
#Look over loaded content data if not empty
|
41
|
+
# If file is under monitoring path - Add to DirStat tree as stable with path,size,mod_time read from file
|
42
|
+
# If file is NOT under monitoring path - skip (not a valid usage)
|
43
|
+
unless $local_content_data.empty?
|
44
|
+
Log.info("Start build data base from loaded file")
|
45
|
+
$local_content_data.each_instance {
|
46
|
+
|_, size, _, mod_time, _, path|
|
47
|
+
# construct sub paths array from full file path:
|
48
|
+
# Example:
|
49
|
+
# instance path = /dir1/dir2/file_name
|
50
|
+
# Sub path 1: /dir1
|
51
|
+
# Sub path 2: /dir1/dir2
|
52
|
+
# Sub path 3: /dir1/dir2/file_name
|
53
|
+
# sub paths would create DirStat objs or FileStat(FileStat create using last sub path).
|
54
|
+
split_path = path.split(File::SEPARATOR)
|
55
|
+
sub_paths = (0..split_path.size-1).inject([]) { |paths, i|
|
56
|
+
paths.push(File.join(*split_path.values_at(0..i)))
|
57
|
+
}
|
58
|
+
# sub_paths holds array => ["/dir1","/dir1/dir2","/dir1/dir2/file_name"]
|
59
|
+
|
60
|
+
# Loop over monitor paths to start build tree under each
|
61
|
+
dir_stat_array.each { | dir_stat|
|
62
|
+
# check if monitor path is one of the sub paths and find it's sub path index
|
63
|
+
# if index is found then it the monitor path
|
64
|
+
# the next index indicates the next sub path to insert to the tree
|
65
|
+
# the index will be raised at each recursive call down the tree
|
66
|
+
sub_paths_index = sub_paths.index(dir_stat.path)
|
67
|
+
next if sub_paths_index.nil? # monitor path was not found. skip this instance.
|
68
|
+
# monitor path was found. Add to tree as stable.
|
69
|
+
dir_stat.state = FileStatEnum::STABLE
|
70
|
+
# start the recursive call with next sub path index
|
71
|
+
dir_stat.load_instance(sub_paths, sub_paths_index+1, size, mod_time)
|
72
|
+
}
|
73
|
+
}
|
74
|
+
Log.info("End build data base from loaded file")
|
75
|
+
end
|
76
|
+
|
44
77
|
# Directories states stored in the priority queue,
|
45
78
|
# where the key (priority) is a time when it should be checked next time.
|
46
79
|
# Priority queue means that all entries arranged by key (time to check) in increasing order.
|
47
80
|
pq = Containers::PriorityQueue.new
|
48
|
-
conf_array.
|
81
|
+
conf_array.each_with_index { |elem, index|
|
49
82
|
priority = (Time.now + elem['scan_period']).to_i
|
50
|
-
|
51
|
-
|
52
|
-
Log.debug1("File monitoring started for: #{elem}")
|
53
|
-
pq.push([priority, elem, dir_stat], -priority)
|
83
|
+
#Log.info("File monitoring started for: #{elem}")
|
84
|
+
pq.push([priority, elem, dir_stat_array[index]], -priority)
|
54
85
|
}
|
55
86
|
|
56
87
|
#init log4r
|
@@ -85,7 +116,9 @@ module FileMonitoring
|
|
85
116
|
end
|
86
117
|
|
87
118
|
unless $testing_memory_active
|
119
|
+
Log.info("Start monitor for dir:%s", dir_stat.path)
|
88
120
|
dir_stat.monitor
|
121
|
+
Log.info("End monitor for dir:%s", dir_stat.path)
|
89
122
|
else
|
90
123
|
$testing_memory_log.info("Start monitor at :#{Time.now}")
|
91
124
|
puts "Start monitor at :#{Time.now}"
|
@@ -23,7 +23,8 @@ module FileMonitoring
|
|
23
23
|
|
24
24
|
# This class holds current state of file and methods to control and report changes
|
25
25
|
class FileStat
|
26
|
-
attr_reader :cycles, :path, :stable_state
|
26
|
+
attr_reader :cycles, :path, :stable_state
|
27
|
+
attr_accessor :state, :size, :modification_time
|
27
28
|
|
28
29
|
DEFAULT_STABLE_STATE = 10
|
29
30
|
|
@@ -33,15 +34,16 @@ module FileMonitoring
|
|
33
34
|
# ==== Arguments:
|
34
35
|
#
|
35
36
|
# * <tt>path</tt> - File location
|
37
|
+
# * <tt>size</tt> - File size [Byte]
|
38
|
+
# * <tt>modification_time</tt> - file mod time [seconds]
|
39
|
+
# * <tt>cycles</tt> - # number of iterations from the last state change.
|
36
40
|
# * <tt>stable_state</tt> - Number of iterations to move unchanged file to stable state
|
37
|
-
def initialize(path, stable_state = DEFAULT_STABLE_STATE
|
41
|
+
def initialize(path, stable_state = DEFAULT_STABLE_STATE)
|
38
42
|
@path ||= path
|
39
43
|
@size = nil
|
40
|
-
@creation_time = nil
|
41
44
|
@modification_time = nil
|
42
|
-
@cycles = 0
|
43
|
-
@
|
44
|
-
@stable_state = stable_state # number of iteration to move unchanged file to stable state
|
45
|
+
@cycles = 0
|
46
|
+
@stable_state = stable_state
|
45
47
|
end
|
46
48
|
|
47
49
|
def set_output_queue(event_queue)
|
@@ -61,23 +63,23 @@ module FileMonitoring
|
|
61
63
|
def monitor
|
62
64
|
file_stats = File.lstat(@path) rescue nil
|
63
65
|
new_state = nil
|
64
|
-
if file_stats
|
66
|
+
if file_stats.nil?
|
65
67
|
new_state = FileStatEnum::NON_EXISTING
|
66
68
|
@size = nil
|
67
|
-
|
69
|
+
#@creation_time = nil
|
68
70
|
@modification_time = nil
|
69
71
|
@cycles = 0
|
70
|
-
elsif @size
|
72
|
+
elsif @size.nil?
|
71
73
|
new_state = FileStatEnum::NEW
|
72
74
|
@size = file_stats.size
|
73
|
-
|
74
|
-
@modification_time = file_stats.mtime.
|
75
|
+
#@creation_time = file_stats.ctime.utc
|
76
|
+
@modification_time = file_stats.mtime.to_i
|
75
77
|
@cycles = 0
|
76
78
|
elsif changed?(file_stats)
|
77
79
|
new_state = FileStatEnum::CHANGED
|
78
80
|
@size = file_stats.size
|
79
|
-
|
80
|
-
@modification_time = file_stats.mtime.
|
81
|
+
#@creation_time = file_stats.ctime.utc
|
82
|
+
@modification_time = file_stats.mtime.to_i
|
81
83
|
@cycles = 0
|
82
84
|
else
|
83
85
|
new_state = FileStatEnum::UNCHANGED
|
@@ -88,14 +90,13 @@ module FileMonitoring
|
|
88
90
|
end
|
89
91
|
|
90
92
|
# The assignment
|
91
|
-
|
93
|
+
set_state(new_state)
|
92
94
|
end
|
93
95
|
|
94
96
|
# Checks that stored file attributes are the same as file attributes taken from file system.
|
95
97
|
def changed?(file_stats)
|
96
|
-
|
97
|
-
|
98
|
-
file_stats.mtime.utc == @modification_time.utc)
|
98
|
+
!((file_stats.size == @size) &&
|
99
|
+
(file_stats.mtime.to_i == @modification_time))
|
99
100
|
end
|
100
101
|
|
101
102
|
def set_event_queue(queue)
|
@@ -103,7 +104,7 @@ module FileMonitoring
|
|
103
104
|
end
|
104
105
|
|
105
106
|
# Sets and writes to the log a new state.
|
106
|
-
def
|
107
|
+
def set_state(new_state)
|
107
108
|
if (@state != new_state or @state == FileStatEnum::CHANGED)
|
108
109
|
@state = new_state
|
109
110
|
if (@@log)
|
@@ -111,9 +112,8 @@ module FileMonitoring
|
|
111
112
|
@@log.outputters[0].flush if Params['log_flush_each_message']
|
112
113
|
end
|
113
114
|
if @event_queue and FileStatEnum::NEW != @state # NEW state is ignored in indexer
|
114
|
-
Log.debug1
|
115
|
-
@event_queue.push([
|
116
|
-
self.modification_time, self.size])
|
115
|
+
Log.debug1("Writing to event queue [%s, %s]", @state, @path)
|
116
|
+
@event_queue.push([@state, self.instance_of?(DirStat), @path, @modification_time, @size])
|
117
117
|
$process_vars.set('monitor to index queue size', @event_queue.size)
|
118
118
|
end
|
119
119
|
end
|
@@ -137,12 +137,51 @@ module FileMonitoring
|
|
137
137
|
#
|
138
138
|
# * <tt>path</tt> - File location
|
139
139
|
# * <tt>stable_state</tt> - Number of iterations to move unchanged directory to stable state
|
140
|
-
def initialize(path, stable_state = DEFAULT_STABLE_STATE
|
140
|
+
def initialize(path, stable_state = DEFAULT_STABLE_STATE)
|
141
141
|
super
|
142
|
-
@dirs = nil
|
143
|
-
@files = nil
|
144
|
-
@non_utf8_paths = {}
|
145
|
-
|
142
|
+
@dirs = nil # Hash: ["path" -> DirStat]
|
143
|
+
@files = nil # Hash: ["path" -> FileStat]
|
144
|
+
@non_utf8_paths = {} # Hash: ["path" -> true|false]
|
145
|
+
end
|
146
|
+
|
147
|
+
# add instance while initializing tree using content data from file
|
148
|
+
# Parameters:
|
149
|
+
# sub_paths - Array of sub paths of the instance which is added to tree
|
150
|
+
# Example:
|
151
|
+
# instance path = /dir1/dir2/file_name
|
152
|
+
# Sub path 1: /dir1
|
153
|
+
# Sub path 2: /dir1/dir2
|
154
|
+
# Sub path 3: /dir1/dir2/file_name
|
155
|
+
# sub paths would create DirStat objs or FileStat(FileStat create using last sub path).
|
156
|
+
# sub_paths_index - the index indicates the next sub path to insert to the tree
|
157
|
+
# the index will be raised at each recursive call down the tree
|
158
|
+
# size - the instance size to insert to the tree
|
159
|
+
# modification_time - the instance modification_time to insert to the tree
|
160
|
+
def load_instance(sub_paths, sub_paths_index, size, modification_time)
|
161
|
+
# initialize dirs and files. This will indicate that the current DirStat is not new.
|
162
|
+
@dirs = {} unless @dirs
|
163
|
+
@files = {} unless @files
|
164
|
+
if sub_paths.size-1 == sub_paths_index
|
165
|
+
# Add File case - index points to last entry - leaf case.
|
166
|
+
file_stat = FileStat.new(sub_paths[sub_paths_index], @stable_state)
|
167
|
+
file_stat.set_event_queue(@event_queue)
|
168
|
+
file_stat.size = size
|
169
|
+
file_stat.modification_time = modification_time
|
170
|
+
file_stat.state = FileStatEnum::STABLE
|
171
|
+
add_file(file_stat)
|
172
|
+
else
|
173
|
+
# Add Dir to tree if not present. index points to new dir path.
|
174
|
+
dir_stat = @dirs[sub_paths[sub_paths_index]]
|
175
|
+
#create new dir if not exist
|
176
|
+
unless dir_stat
|
177
|
+
dir_stat = DirStat.new(sub_paths[sub_paths_index], @stable_state)
|
178
|
+
dir_stat.state = FileStatEnum::STABLE
|
179
|
+
dir_stat.set_event_queue(@event_queue)
|
180
|
+
add_dir(dir_stat)
|
181
|
+
end
|
182
|
+
# continue recursive call on tree with next sub path index
|
183
|
+
dir_stat.load_instance(sub_paths, sub_paths_index+1, size, modification_time)
|
184
|
+
end
|
146
185
|
end
|
147
186
|
|
148
187
|
# Adds directory for monitoring.
|
@@ -218,7 +257,7 @@ module FileMonitoring
|
|
218
257
|
end
|
219
258
|
|
220
259
|
# The assignment
|
221
|
-
|
260
|
+
set_state(new_state)
|
222
261
|
end
|
223
262
|
|
224
263
|
# Updates the files and directories hashes and globs the directory for changes.
|
@@ -270,7 +309,7 @@ module FileMonitoring
|
|
270
309
|
# change state only for existing directories
|
271
310
|
# newly added directories have to remain with NEW state
|
272
311
|
was_changed = true
|
273
|
-
ds = DirStat.new(file, self.stable_state
|
312
|
+
ds = DirStat.new(file, self.stable_state)
|
274
313
|
ds.set_event_queue(@event_queue) unless @event_queue.nil?
|
275
314
|
ds.monitor
|
276
315
|
add_dir(ds)
|
@@ -282,11 +321,7 @@ module FileMonitoring
|
|
282
321
|
was_changed = true
|
283
322
|
# check if file exist in content data cache - set state to STABLE
|
284
323
|
file_state = FileStatEnum::NON_EXISTING
|
285
|
-
|
286
|
-
file_state = FileStatEnum::STABLE
|
287
|
-
end
|
288
|
-
fs = FileStat.new(file, self.stable_state, @content_data_cache, file_state)
|
289
|
-
|
324
|
+
fs = FileStat.new(file, self.stable_state)
|
290
325
|
fs.set_event_queue(@event_queue) unless @event_queue.nil?
|
291
326
|
fs.monitor
|
292
327
|
add_file(fs)
|
data/lib/log.rb
CHANGED
@@ -141,34 +141,70 @@ module Log
|
|
141
141
|
end
|
142
142
|
|
143
143
|
# Log info massages
|
144
|
-
|
144
|
+
# params:
|
145
|
+
# msg, *args - Works to construct a string using: msg % args
|
146
|
+
# Examples:
|
147
|
+
# "hello" # no args provided
|
148
|
+
# "Time is %s. have a good day %s", Time.now, "Sir"
|
149
|
+
# Note: Use ONLY %s in msg. Since %d will crush for nil objects, while %s will print empty string.
|
150
|
+
# Implicit to_s is used to convert arg to %s.
|
151
|
+
# If no to_s exists then ruby uses inspection.
|
152
|
+
def Log.info(msg, *args)
|
145
153
|
Log.init if @log4r.nil?
|
154
|
+
msg = msg % args
|
146
155
|
@log4r.info(msg_with_caller(msg))
|
147
156
|
Log.flush if Params['log_flush_each_message']
|
148
157
|
end
|
149
158
|
|
150
159
|
# Log debug level 1 massages
|
151
|
-
|
160
|
+
# params:
|
161
|
+
# msg, *args - Works to construct a string using: msg % args
|
162
|
+
# Examples:
|
163
|
+
# "hello" # no args provided
|
164
|
+
# "Time is %s. have a good day %s", Time.now, "Sir"
|
165
|
+
# Note: Use ONLY %s in msg. Since %d will crush for nil objects, while %s will print empty string.
|
166
|
+
# Implicit to_s is used to convert arg to %s.
|
167
|
+
# If no to_s exists then ruby uses inspection.
|
168
|
+
def Log.debug1(msg, *args)
|
152
169
|
if Params['log_debug_level'] >= 1
|
153
170
|
Log.init if @log4r.nil?
|
171
|
+
msg = msg % args
|
154
172
|
@log4r.debug(msg_with_caller(msg))
|
155
173
|
Log.flush if Params['log_flush_each_message']
|
156
174
|
end
|
157
175
|
end
|
158
176
|
|
159
177
|
# Log debug level 2 massages
|
160
|
-
|
178
|
+
# params:
|
179
|
+
# msg, *args - Works to construct a string using: msg % args
|
180
|
+
# Examples:
|
181
|
+
# "hello" # no args provided
|
182
|
+
# "Time is %s. have a good day %s", Time.now, "Sir"
|
183
|
+
# Note: Use ONLY %s in msg. Since %d will crush for nil objects, while %s will print empty string.
|
184
|
+
# Implicit to_s is used to convert arg to %s.
|
185
|
+
# If no to_s exists then ruby uses inspection.
|
186
|
+
def Log.debug2(msg, *args)
|
161
187
|
if Params['log_debug_level'] >= 2
|
162
188
|
Log.init if @log4r.nil?
|
189
|
+
msg = msg % args
|
163
190
|
@log4r.debug(msg_with_caller(msg))
|
164
191
|
Log.flush if Params['log_flush_each_message']
|
165
192
|
end
|
166
193
|
end
|
167
194
|
|
168
195
|
# Log debug level 3 massages
|
169
|
-
|
196
|
+
# params:
|
197
|
+
# msg, *args - Works to construct a string using: msg % args
|
198
|
+
# Examples:
|
199
|
+
# "hello" # no args provided
|
200
|
+
# "Time is %s. have a good day %s", Time.now, "Sir"
|
201
|
+
# Note: Use ONLY %s in msg. Since %d will crush for nil objects, while %s will print empty string.
|
202
|
+
# Implicit to_s is used to convert arg to %s.
|
203
|
+
# If no to_s exists then ruby uses inspection.
|
204
|
+
def Log.debug3(msg, *args)
|
170
205
|
if Params['log_debug_level'] >= 3
|
171
206
|
Log.init if @log4r.nil?
|
207
|
+
msg = msg % args
|
172
208
|
@log4r.debug(msg_with_caller(msg))
|
173
209
|
Log.flush if Params['log_flush_each_message']
|
174
210
|
end
|