file-digests 0.0.9 → 0.0.14
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.
- checksums.yaml +4 -4
- data/bin/file-digests +2 -2
- data/bin/file-digests-test +2 -2
- data/lib/file-digests.rb +32 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa2168306bdb4d923daef330ec22f3381bc2b3106f56a162b80dae94721e7799
|
4
|
+
data.tar.gz: f43dd24befade5a72e4fd0b878f7bd2abbd06266923c4d062b3c50b1d624b1e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 051d97686878d0d53cf3e2206c5e1f2ee8b0d4e678a7f8f5cc1edeb3fc5e34d706b6afdc2dc9c75a68863e9cc1a6afb6f14c4346ac46f2007c72427b38ed2ee2
|
7
|
+
data.tar.gz: a94aeec79e617d803f6f3e81bbabe07c68c0e287a0413ade53a4f085c007c92874f96432a5eb7505c4ca9057c4f5525a40f1f560f6ba05a258d0e78b4366bc7d
|
data/bin/file-digests
CHANGED
data/bin/file-digests-test
CHANGED
data/lib/file-digests.rb
CHANGED
@@ -30,10 +30,8 @@ module FileDigests
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.perform_check
|
33
|
-
|
34
|
-
|
35
|
-
checker = Checker.new files_path, digest_database_path
|
36
|
-
checker.check
|
33
|
+
checker = Checker.new ARGV[0], ARGV[1]
|
34
|
+
checker.perform_check
|
37
35
|
end
|
38
36
|
|
39
37
|
class DigestDatabase
|
@@ -154,22 +152,36 @@ module FileDigests
|
|
154
152
|
|
155
153
|
class Checker
|
156
154
|
def initialize files_path, digest_database_path
|
157
|
-
@
|
158
|
-
@files_path = files_path
|
155
|
+
@files_path = Pathname.new(FileDigests::patch_path_string(files_path || ".")).cleanpath
|
159
156
|
@prefix_to_remove = @files_path.to_s + '/'
|
160
157
|
|
161
|
-
unless
|
162
|
-
|
158
|
+
raise "Files path must be a readable directory" unless (File.directory?(@files_path) && File.readable?(@files_path))
|
159
|
+
|
160
|
+
@digest_database_path = if digest_database_path
|
161
|
+
Pathname.new(FileDigests::patch_path_string(digest_database_path)).cleanpath
|
162
|
+
else
|
163
|
+
@files_path + '.file-digests.sqlite'
|
164
|
+
end
|
165
|
+
|
166
|
+
if File.directory?(@digest_database_path)
|
167
|
+
@digest_database_path = @digest_database_path + '.file-digests.sqlite'
|
168
|
+
end
|
169
|
+
|
170
|
+
if @files_path == @digest_database_path.dirname
|
163
171
|
@skip_file_digests_sqlite = true
|
164
172
|
end
|
165
173
|
|
166
|
-
FileDigests::ensure_dir_exists @
|
167
|
-
FileDigests::ensure_dir_exists digest_database_path.dirname
|
174
|
+
FileDigests::ensure_dir_exists @digest_database_path.dirname
|
168
175
|
|
169
|
-
@
|
176
|
+
if File.exist?(@digest_database_path.dirname + '.file-digests.sha512')
|
177
|
+
@use_sha512 = true
|
178
|
+
end
|
179
|
+
|
180
|
+
@digest_database = DigestDatabase.new @digest_database_path
|
181
|
+
@counters = {good: 0, updated: 0, new: 0, missing: 0, renamed: 0, likely_damaged: 0, exceptions: 0}
|
170
182
|
end
|
171
183
|
|
172
|
-
def
|
184
|
+
def perform_check
|
173
185
|
FileDigests::measure_time do
|
174
186
|
walk_files do |filename|
|
175
187
|
process_file filename
|
@@ -206,25 +218,27 @@ module FileDigests
|
|
206
218
|
return if stat.socket?
|
207
219
|
|
208
220
|
if @skip_file_digests_sqlite
|
209
|
-
|
210
|
-
return if
|
211
|
-
return if
|
221
|
+
basename = File.basename(filename)
|
222
|
+
return if basename == '.file-digests.sha512'
|
223
|
+
return if basename == '.file-digests.sqlite'
|
224
|
+
return if basename == '.file-digests.sqlite-wal'
|
225
|
+
return if basename == '.file-digests.sqlite-shm'
|
212
226
|
end
|
213
227
|
|
214
228
|
@digest_database.insert_or_update(
|
215
|
-
filename.delete_prefix(@prefix_to_remove).unicode_normalize(:nfkc),
|
229
|
+
filename.delete_prefix(@prefix_to_remove).encode('utf-8', universal_newline: true).unicode_normalize(:nfkc),
|
216
230
|
stat.mtime.utc.strftime('%Y-%m-%d %H:%M:%S'),
|
217
231
|
get_file_digest(filename),
|
218
232
|
@counters
|
219
233
|
)
|
220
234
|
rescue => exception
|
221
235
|
@counters[:exceptions] += 1
|
222
|
-
STDERR.puts "EXCEPTION: #{filename}: #{exception.message}"
|
236
|
+
STDERR.puts "EXCEPTION: #{filename.encode('utf-8', universal_newline: true)}: #{exception.message}"
|
223
237
|
end
|
224
238
|
|
225
239
|
def get_file_digest filename
|
226
240
|
File.open(filename, 'rb') do |io|
|
227
|
-
digest = Digest::SHA512.new
|
241
|
+
digest = (@use_sha512 ? Digest::SHA512 : Digest::SHA256).new
|
228
242
|
buffer = ""
|
229
243
|
while io.read(40960, buffer)
|
230
244
|
digest.update(buffer)
|