Class: FileDigests::Checker
- Inherits:
-
Object
- Object
- FileDigests::Checker
- Defined in:
- lib/file-digests.rb
Instance Method Summary collapse
-
#initialize(files_path, digest_database_path, options = {}) ⇒ Checker
constructor
A new instance of Checker.
- #perform_check ⇒ Object
Constructor Details
#initialize(files_path, digest_database_path, options = {}) ⇒ Checker
Returns a new instance of Checker.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/file-digests.rb', line 142 def initialize files_path, digest_database_path, = {} @options = @files_path = cleanup_path(files_path || ".") @prefix_to_remove = @files_path.to_s + '/' raise "Files path must be a readable directory" unless (File.directory?(@files_path) && File.readable?(@files_path)) @digest_database_path = if digest_database_path cleanup_path(digest_database_path) else @files_path + '.file-digests.sqlite' end if File.directory?(@digest_database_path) @digest_database_path = @digest_database_path + '.file-digests.sqlite' end if @files_path == @digest_database_path.dirname @skip_file_digests_sqlite = true end ensure_dir_exists @digest_database_path.dirname # Please do not use this flag, support for sha512 is here for backward compatibility, and one day it will be removed. if File.exist?(@digest_database_path.dirname + '.file-digests.sha512') @use_sha512 = true end @digest_database = DigestDatabase.new @digest_database_path, @options @counters = {good: 0, updated: 0, new: 0, missing: 0, renamed: 0, likely_damaged: 0, exceptions: 0} end |
Instance Method Details
#perform_check ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/file-digests.rb', line 174 def perform_check measure_time do walk_files do |filename| process_file filename end end @digest_database.track_renames @counters if @digest_database.any_missing_files? @digest_database.print_missing_files if !@options[:test_only] && (@options[:auto] || confirm("Remove missing files from the database")) @digest_database.remove_missing_files end end if @counters[:likely_damaged] > 0 || @counters[:exceptions] > 0 STDERR.puts "ERRORS WERE OCCURRED" end puts @counters.inspect end |