file-digests 0.0.28 → 0.0.33
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/lib/file-digests.rb +32 -10
- 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: 68dea8d33894b138d5908dcf27fef7800a17af8f1441fd043876248414ad9525
|
4
|
+
data.tar.gz: da5c89c26fc95ddeaa6b8443193293490e71f41bc4ed21e00415c5937661833e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05e700dedeebde8e472e8adf6b0eedb6c3692b919b3d478a041c8e8110375daae7dd926cd9c33c46379976730f0fb0610880a57524aa44e0764fa169a4020fad
|
7
|
+
data.tar.gz: c0e954b6250223e53ec0823f328bd808886f9566ecf373ceaaba5da7a079ae76e18dfba3cf81bfad0741ea8dfdb87c1715c81f8af72094b77abe014fc59727ef
|
data/lib/file-digests.rb
CHANGED
@@ -75,7 +75,12 @@ class FileDigests
|
|
75
75
|
options[:quiet] = true
|
76
76
|
end
|
77
77
|
|
78
|
-
opts.on(
|
78
|
+
opts.on(
|
79
|
+
"-t", "--test",
|
80
|
+
"Perform a test to verify directory contents.",
|
81
|
+
"Compare actual files with the stored digests, check if any files are missing.",
|
82
|
+
"Digest database will not be modified."
|
83
|
+
) do
|
79
84
|
options[:test_only] = true
|
80
85
|
end
|
81
86
|
|
@@ -124,7 +129,9 @@ class FileDigests
|
|
124
129
|
|
125
130
|
@digest_database_path = digest_database_path ? cleanup_path(digest_database_path) : @files_path
|
126
131
|
@digest_database_path += ".file-digests.sqlite" if File.directory?(@digest_database_path)
|
127
|
-
|
132
|
+
ensure_dir_exist @digest_database_path.dirname
|
133
|
+
|
134
|
+
@digest_database_files = ["#{@digest_database_path}", "#{@digest_database_path}-wal", "#{@digest_database_path}-shm"]
|
128
135
|
|
129
136
|
if @options[:verbose]
|
130
137
|
puts "Target directory: #{@files_path}"
|
@@ -227,6 +234,7 @@ class FileDigests
|
|
227
234
|
end
|
228
235
|
|
229
236
|
nested_transaction do
|
237
|
+
puts "Tracking renames..." if @options[:verbose]
|
230
238
|
track_renames
|
231
239
|
end
|
232
240
|
|
@@ -237,6 +245,7 @@ class FileDigests
|
|
237
245
|
print_missing_files
|
238
246
|
if !@options[:test_only] && (@options[:auto] || confirm("Remove missing files from the database"))
|
239
247
|
nested_transaction do
|
248
|
+
puts "Removing missing files..." if @options[:verbose]
|
240
249
|
remove_missing_files
|
241
250
|
end
|
242
251
|
end
|
@@ -247,6 +256,7 @@ class FileDigests
|
|
247
256
|
if any_missing_files? || any_likely_damaged? || any_exceptions?
|
248
257
|
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."
|
249
258
|
else
|
259
|
+
puts "Updating database to a new digest algorithm..." if @options[:verbose]
|
250
260
|
@new_digests.each do |old_digest, new_digest|
|
251
261
|
update_digest_to_new_digest new_digest, old_digest
|
252
262
|
end
|
@@ -261,12 +271,15 @@ class FileDigests
|
|
261
271
|
|
262
272
|
set_metadata(@options[:test_only] ? "latest_test_only_check_time" : "latest_complete_check_time", time_to_database(Time.now))
|
263
273
|
|
264
|
-
execute "PRAGMA optimize"
|
265
|
-
execute "VACUUM"
|
266
|
-
execute "PRAGMA wal_checkpoint(TRUNCATE)"
|
267
|
-
|
268
274
|
print_counters
|
269
275
|
end
|
276
|
+
|
277
|
+
puts "Performing database maintenance..." if @options[:verbose]
|
278
|
+
execute "PRAGMA optimize"
|
279
|
+
execute "VACUUM"
|
280
|
+
execute "PRAGMA wal_checkpoint(TRUNCATE)"
|
281
|
+
|
282
|
+
hide_database_files
|
270
283
|
end
|
271
284
|
|
272
285
|
def show_duplicates
|
@@ -296,9 +309,7 @@ class FileDigests
|
|
296
309
|
|
297
310
|
raise "File is not readable" unless stat.readable?
|
298
311
|
|
299
|
-
if filename
|
300
|
-
filename == "#{@digest_database_path}-wal" ||
|
301
|
-
filename == "#{@digest_database_path}-shm"
|
312
|
+
if @digest_database_files.include?(filename)
|
302
313
|
puts "SKIPPING DATABASE FILE: #{filename}" if @options[:verbose]
|
303
314
|
return
|
304
315
|
end
|
@@ -460,6 +471,16 @@ class FileDigests
|
|
460
471
|
time.utc.strftime("%Y-%m-%d %H:%M:%S")
|
461
472
|
end
|
462
473
|
|
474
|
+
def hide_database_files
|
475
|
+
if Gem.win_platform?
|
476
|
+
@digest_database_files.each do |file|
|
477
|
+
if File.exist?(file)
|
478
|
+
system "attrib", "+H", file, exception: true
|
479
|
+
end
|
480
|
+
end
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
463
484
|
|
464
485
|
# Filesystem-related helpers
|
465
486
|
|
@@ -471,7 +492,7 @@ class FileDigests
|
|
471
492
|
Pathname.new(patch_path_string(path)).cleanpath
|
472
493
|
end
|
473
494
|
|
474
|
-
def
|
495
|
+
def ensure_dir_exist path
|
475
496
|
if File.exist?(path)
|
476
497
|
unless File.directory?(path)
|
477
498
|
raise "#{path} is not a directory"
|
@@ -482,6 +503,7 @@ class FileDigests
|
|
482
503
|
end
|
483
504
|
|
484
505
|
def walk_files
|
506
|
+
puts "Gathering the list of files..." if @options[:verbose]
|
485
507
|
Dir.glob(@files_path + "**" + "*", File::FNM_DOTMATCH) do |filename|
|
486
508
|
yield filename
|
487
509
|
end
|