file-digests 0.0.14 → 0.0.15

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/file-digests.rb +36 -30
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa2168306bdb4d923daef330ec22f3381bc2b3106f56a162b80dae94721e7799
4
- data.tar.gz: f43dd24befade5a72e4fd0b878f7bd2abbd06266923c4d062b3c50b1d624b1e9
3
+ metadata.gz: 573cd697002f30d083625d586b4d03caf8c0f2cb763bed75e2bc9ac0a8b03612
4
+ data.tar.gz: 7cfbef9cdf7a9110c6b84b27591a498960515842675fabf6bf5512a78d7e54bc
5
5
  SHA512:
6
- metadata.gz: 051d97686878d0d53cf3e2206c5e1f2ee8b0d4e678a7f8f5cc1edeb3fc5e34d706b6afdc2dc9c75a68863e9cc1a6afb6f14c4346ac46f2007c72427b38ed2ee2
7
- data.tar.gz: a94aeec79e617d803f6f3e81bbabe07c68c0e287a0413ade53a4f085c007c92874f96432a5eb7505c4ca9057c4f5525a40f1f560f6ba05a258d0e78b4366bc7d
6
+ metadata.gz: 4916e667dccfb630a31fdaa74271a9c85a5f28a81f28143a4f5b406784e0e78652a29ff8e3fd9ff6507a5d90a4d9baacd2385f7de169f2c9dda6dc0f3b58866b
7
+ data.tar.gz: be5ae679122bbcffc703940b113e8d1e1057e46f7ce61ead1f52664f6b147bbd9c201d56b7faeafef29da30297cfde2e40f38c8e9400d615b9bbc6e630557259
@@ -8,27 +8,6 @@ require 'sqlite3'
8
8
 
9
9
  module FileDigests
10
10
 
11
- def self.ensure_dir_exists path
12
- if File.exist?(path)
13
- unless File.directory?(path)
14
- raise "#{path} is not a directory"
15
- end
16
- else
17
- FileUtils.mkdir_p path
18
- end
19
- end
20
-
21
- def self.measure_time
22
- start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
23
- yield
24
- elapsed = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start).to_i
25
- puts "Elapsed time: #{elapsed / 3600}h #{(elapsed % 3600) / 60}m #{elapsed % 60}s" unless QUIET
26
- end
27
-
28
- def self.patch_path_string path
29
- Gem.win_platform? ? path.gsub(/\\/, '/') : path
30
- end
31
-
32
11
  def self.perform_check
33
12
  checker = Checker.new ARGV[0], ARGV[1]
34
13
  checker.perform_check
@@ -152,13 +131,13 @@ module FileDigests
152
131
 
153
132
  class Checker
154
133
  def initialize files_path, digest_database_path
155
- @files_path = Pathname.new(FileDigests::patch_path_string(files_path || ".")).cleanpath
134
+ @files_path = cleanup_path(files_path || ".")
156
135
  @prefix_to_remove = @files_path.to_s + '/'
157
136
 
158
137
  raise "Files path must be a readable directory" unless (File.directory?(@files_path) && File.readable?(@files_path))
159
138
 
160
139
  @digest_database_path = if digest_database_path
161
- Pathname.new(FileDigests::patch_path_string(digest_database_path)).cleanpath
140
+ cleanup_path(digest_database_path)
162
141
  else
163
142
  @files_path + '.file-digests.sqlite'
164
143
  end
@@ -171,7 +150,7 @@ module FileDigests
171
150
  @skip_file_digests_sqlite = true
172
151
  end
173
152
 
174
- FileDigests::ensure_dir_exists @digest_database_path.dirname
153
+ ensure_dir_exists @digest_database_path.dirname
175
154
 
176
155
  if File.exist?(@digest_database_path.dirname + '.file-digests.sha512')
177
156
  @use_sha512 = true
@@ -182,7 +161,7 @@ module FileDigests
182
161
  end
183
162
 
184
163
  def perform_check
185
- FileDigests::measure_time do
164
+ measure_time do
186
165
  walk_files do |filename|
187
166
  process_file filename
188
167
  end
@@ -197,11 +176,7 @@ module FileDigests
197
176
  puts @counters.inspect
198
177
  end
199
178
 
200
- def walk_files
201
- Dir.glob(@files_path + '**' + '*', File::FNM_DOTMATCH) do |filename|
202
- yield filename
203
- end
204
- end
179
+ private
205
180
 
206
181
  def process_file filename
207
182
  return if File.symlink? filename
@@ -236,6 +211,30 @@ module FileDigests
236
211
  STDERR.puts "EXCEPTION: #{filename.encode('utf-8', universal_newline: true)}: #{exception.message}"
237
212
  end
238
213
 
214
+ def patch_path_string path
215
+ Gem.win_platform? ? path.gsub(/\\/, '/') : path
216
+ end
217
+
218
+ def cleanup_path path
219
+ Pathname.new(patch_path_string(digest_database_path)).cleanpath
220
+ end
221
+
222
+ def ensure_dir_exists path
223
+ if File.exist?(path)
224
+ unless File.directory?(path)
225
+ raise "#{path} is not a directory"
226
+ end
227
+ else
228
+ FileUtils.mkdir_p path
229
+ end
230
+ end
231
+
232
+ def walk_files
233
+ Dir.glob(@files_path + '**' + '*', File::FNM_DOTMATCH) do |filename|
234
+ yield filename
235
+ end
236
+ end
237
+
239
238
  def get_file_digest filename
240
239
  File.open(filename, 'rb') do |io|
241
240
  digest = (@use_sha512 ? Digest::SHA512 : Digest::SHA256).new
@@ -247,5 +246,12 @@ module FileDigests
247
246
  end
248
247
  end
249
248
 
249
+ def measure_time
250
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
251
+ yield
252
+ elapsed = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start).to_i
253
+ puts "Elapsed time: #{elapsed / 3600}h #{(elapsed % 3600) / 60}m #{elapsed % 60}s" unless QUIET
254
+ end
255
+
250
256
  end
251
257
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file-digests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav Senotrusov