Class: FileMonitoring::FileStat
- Inherits:
-
Object
- Object
- FileMonitoring::FileStat
- Defined in:
- lib/file_monitoring/monitor_path.rb
Overview
This class holds current state of file and methods to control and report changes
Constant Summary collapse
- @@digest =
Digest::SHA1.new
Instance Attribute Summary collapse
-
#cycles ⇒ Object
Returns the value of attribute cycles.
-
#indexed ⇒ Object
Returns the value of attribute indexed.
-
#marked ⇒ Object
Returns the value of attribute marked.
-
#modification_time ⇒ Object
Returns the value of attribute modification_time.
-
#path ⇒ Object
Returns the value of attribute path.
-
#size ⇒ Object
Returns the value of attribute size.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Checks whether path and state are the same as of the argument.
-
#changed?(file_stats) ⇒ Boolean
Checks that stored file attributes are the same as file attributes taken from file system.
- #index ⇒ Object
-
#initialize(path, state = FileStatEnum::NEW, size = -1,, mod_time = -1,, indexed = false, cycles = 0) ⇒ FileStat
constructor
Initializes new file monitoring object ==== Arguments:.
-
#to_s(indent = 0) ⇒ Object
Returns path and state of the file with indentation.
Constructor Details
#initialize(path, state = FileStatEnum::NEW, size = -1,, mod_time = -1,, indexed = false, cycles = 0) ⇒ FileStat
Initializes new file monitoring object
Arguments:
-
path
- FileDir path -
state
- state. see class FileStatEnum. Default is NEW -
size
- File size [Byte]. Default is -1 (will be set later during monitor) todo:used? -
mod_time
- file mod time [seconds]. Default is -1 (will be set later during monitor) -
indexed
- Initialize file which is already indexed (used for dir rename case) -
cycles
- Initialize file which already passed monitor cycles (used for dir rename case)
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/file_monitoring/monitor_path.rb', line 65 def initialize(path, state=FileStatEnum::NEW, size=-1, mod_time=-1, indexed=false, cycles=0) # File\Dir path @path = path # File size @size = size # File modification time @modification_time = mod_time # File sate. see class FileStatEnum for states. @state = state # indicates if path EXISTS in file system. # If true, file will not be removed during removed_unmarked_paths phase. @marked = false # Number of times that file was monitored and not changed. # When @cycles exceeds ::FileMonitoring::stable_state, @state is set to Stable and can be indexed. @cycles = cycles # flag to indicate if file was indexed @indexed = indexed end |
Instance Attribute Details
#cycles ⇒ Object
Returns the value of attribute cycles.
52 53 54 |
# File 'lib/file_monitoring/monitor_path.rb', line 52 def cycles @cycles end |
#indexed ⇒ Object
Returns the value of attribute indexed.
52 53 54 |
# File 'lib/file_monitoring/monitor_path.rb', line 52 def indexed @indexed end |
#marked ⇒ Object
Returns the value of attribute marked.
52 53 54 |
# File 'lib/file_monitoring/monitor_path.rb', line 52 def marked @marked end |
#modification_time ⇒ Object
Returns the value of attribute modification_time.
52 53 54 |
# File 'lib/file_monitoring/monitor_path.rb', line 52 def modification_time @modification_time end |
#path ⇒ Object
Returns the value of attribute path.
52 53 54 |
# File 'lib/file_monitoring/monitor_path.rb', line 52 def path @path end |
#size ⇒ Object
Returns the value of attribute size.
52 53 54 |
# File 'lib/file_monitoring/monitor_path.rb', line 52 def size @size end |
#state ⇒ Object
Returns the value of attribute state.
52 53 54 |
# File 'lib/file_monitoring/monitor_path.rb', line 52 def state @state end |
Instance Method Details
#==(other) ⇒ Object
Checks whether path and state are the same as of the argument
120 121 122 |
# File 'lib/file_monitoring/monitor_path.rb', line 120 def == (other) @path == other.path end |
#changed?(file_stats) ⇒ Boolean
Checks that stored file attributes are the same as file attributes taken from file system.
114 115 116 117 |
# File 'lib/file_monitoring/monitor_path.rb', line 114 def changed?(file_stats) !((file_stats.size == @size) && (file_stats.mtime.to_i == @modification_time)) end |
#index ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/file_monitoring/monitor_path.rb', line 90 def index if !@indexed and FileStatEnum::STABLE == @state #index file @@digest.reset begin File.open(@path, 'rb') { |f| while buffer = f.read(16384) do @@digest << buffer end } $local_content_data_lock.synchronize{ $local_content_data.add_instance(@@digest.hexdigest.downcase, @size, Params['local_server_name'], @path, @modification_time) } #$process_vars.inc('indexed_files') $indexed_file_count += 1 @indexed = true rescue Log.warning("Indexed path'#{@path}' does not exist. Probably file changed") if @@log end end end |
#to_s(indent = 0) ⇒ Object
Returns path and state of the file with indentation
125 126 127 |
# File 'lib/file_monitoring/monitor_path.rb', line 125 def to_s (indent = 0) (" " * indent) + path.to_s + " : " + state.to_s end |