file-digests 0.0.27 → 0.0.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/file-digests.rb +33 -13
- 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: fd4c4c18335dad84ab6622b5dd3f46c5edfd513d4655dfc014cf39a6816dd834
|
4
|
+
data.tar.gz: df06f84f85f20229aaea1afa3725702e438c972b4cbbc87b064a98ee8315cd51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1ec44bf23a675c462a32171ae86683f6e48718aae2bb9be00b72286cbdbe87e47f04be3aa9c3f41a9e40e99ee58d3e8a0500fecd89f3413e88b3d03eb42ff57
|
7
|
+
data.tar.gz: 35c548835a8c987bff317d91fcfd71abc69db8660bd30543ebea5022b93b89d9814b42e64a7d168eacef77c085ba6107f618757cb6ad047183f78155f5b4e9ba
|
data/lib/file-digests.rb
CHANGED
@@ -101,16 +101,19 @@ class FileDigests
|
|
101
101
|
initialize_database
|
102
102
|
|
103
103
|
@db.transaction(:exclusive) do
|
104
|
-
if
|
105
|
-
if @
|
106
|
-
@
|
104
|
+
if db_digest_algorithm = get_metadata("digest_algorithm")
|
105
|
+
if @digest_algorithm = canonical_digest_algorithm_name(db_digest_algorithm)
|
106
|
+
if @options[:digest_algorithm] && @options[:digest_algorithm] != @digest_algorithm
|
107
|
+
@new_digest_algorithm = @options[:digest_algorithm]
|
108
|
+
end
|
109
|
+
else
|
110
|
+
raise "Database contains data for unsupported digest algorithm: #{db_digest_algorithm}"
|
107
111
|
end
|
108
112
|
else
|
109
113
|
@digest_algorithm = (@options[:digest_algorithm] || "BLAKE2b512")
|
110
114
|
set_metadata "digest_algorithm", @digest_algorithm
|
111
115
|
end
|
112
116
|
end
|
113
|
-
|
114
117
|
puts "Using #{@digest_algorithm} digest algorithm" if @options[:verbose]
|
115
118
|
end
|
116
119
|
|
@@ -121,7 +124,9 @@ class FileDigests
|
|
121
124
|
|
122
125
|
@digest_database_path = digest_database_path ? cleanup_path(digest_database_path) : @files_path
|
123
126
|
@digest_database_path += ".file-digests.sqlite" if File.directory?(@digest_database_path)
|
124
|
-
|
127
|
+
ensure_dir_exist @digest_database_path.dirname
|
128
|
+
|
129
|
+
@digest_database_files = ["#{@digest_database_path}", "#{@digest_database_path}-wal", "#{@digest_database_path}-shm"]
|
125
130
|
|
126
131
|
if @options[:verbose]
|
127
132
|
puts "Target directory: #{@files_path}"
|
@@ -224,6 +229,7 @@ class FileDigests
|
|
224
229
|
end
|
225
230
|
|
226
231
|
nested_transaction do
|
232
|
+
puts "Tracking renames..." if @options[:verbose]
|
227
233
|
track_renames
|
228
234
|
end
|
229
235
|
|
@@ -234,6 +240,7 @@ class FileDigests
|
|
234
240
|
print_missing_files
|
235
241
|
if !@options[:test_only] && (@options[:auto] || confirm("Remove missing files from the database"))
|
236
242
|
nested_transaction do
|
243
|
+
puts "Removing missing files..." if @options[:verbose]
|
237
244
|
remove_missing_files
|
238
245
|
end
|
239
246
|
end
|
@@ -244,6 +251,7 @@ class FileDigests
|
|
244
251
|
if any_missing_files? || any_likely_damaged? || any_exceptions?
|
245
252
|
STDERR.puts "ERROR: New digest algorithm will not be in effect until there are files that are missing, likely damaged, or processed with an exception."
|
246
253
|
else
|
254
|
+
puts "Updating database to a new digest algorithm..." if @options[:verbose]
|
247
255
|
@new_digests.each do |old_digest, new_digest|
|
248
256
|
update_digest_to_new_digest new_digest, old_digest
|
249
257
|
end
|
@@ -258,12 +266,15 @@ class FileDigests
|
|
258
266
|
|
259
267
|
set_metadata(@options[:test_only] ? "latest_test_only_check_time" : "latest_complete_check_time", time_to_database(Time.now))
|
260
268
|
|
261
|
-
execute "PRAGMA optimize"
|
262
|
-
execute "VACUUM"
|
263
|
-
execute "PRAGMA wal_checkpoint(TRUNCATE)"
|
264
|
-
|
265
269
|
print_counters
|
266
270
|
end
|
271
|
+
|
272
|
+
puts "Performing database maintenance..." if @options[:verbose]
|
273
|
+
execute "PRAGMA optimize"
|
274
|
+
execute "VACUUM"
|
275
|
+
execute "PRAGMA wal_checkpoint(TRUNCATE)"
|
276
|
+
|
277
|
+
hide_database_files
|
267
278
|
end
|
268
279
|
|
269
280
|
def show_duplicates
|
@@ -293,9 +304,7 @@ class FileDigests
|
|
293
304
|
|
294
305
|
raise "File is not readable" unless stat.readable?
|
295
306
|
|
296
|
-
if filename
|
297
|
-
filename == "#{@digest_database_path}-wal" ||
|
298
|
-
filename == "#{@digest_database_path}-shm"
|
307
|
+
if @digest_database_files.include?(filename)
|
299
308
|
puts "SKIPPING DATABASE FILE: #{filename}" if @options[:verbose]
|
300
309
|
return
|
301
310
|
end
|
@@ -457,6 +466,16 @@ class FileDigests
|
|
457
466
|
time.utc.strftime("%Y-%m-%d %H:%M:%S")
|
458
467
|
end
|
459
468
|
|
469
|
+
def hide_database_files
|
470
|
+
if Gem.win_platform?
|
471
|
+
@digest_database_files.each do |file|
|
472
|
+
if File.exist?(file)
|
473
|
+
system "attrib", "+H", file, exception: true
|
474
|
+
end
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
460
479
|
|
461
480
|
# Filesystem-related helpers
|
462
481
|
|
@@ -468,7 +487,7 @@ class FileDigests
|
|
468
487
|
Pathname.new(patch_path_string(path)).cleanpath
|
469
488
|
end
|
470
489
|
|
471
|
-
def
|
490
|
+
def ensure_dir_exist path
|
472
491
|
if File.exist?(path)
|
473
492
|
unless File.directory?(path)
|
474
493
|
raise "#{path} is not a directory"
|
@@ -479,6 +498,7 @@ class FileDigests
|
|
479
498
|
end
|
480
499
|
|
481
500
|
def walk_files
|
501
|
+
puts "Gathering the list of files..." if @options[:verbose]
|
482
502
|
Dir.glob(@files_path + "**" + "*", File::FNM_DOTMATCH) do |filename|
|
483
503
|
yield filename
|
484
504
|
end
|