file-digests 0.0.24 → 0.0.25
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 +12 -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: 3bae6b10fe6496192c178f9139003b8d5a19774c70d957fd83f83ee91540cff9
|
4
|
+
data.tar.gz: 15d2965cb47eaeedec5dd56a0fe0a30e2f686e72d80f823416a351326d034ba8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89b7fc7eea7a5b87f2cc23ea794ac1b2f85e9b367825694876afd91c9206c438a8df91487aaa4872e7b24480e0e5eb25b2750237318fc63305c605aa7fa372a4
|
7
|
+
data.tar.gz: 8fedea5e7034824276ea1f315543d5248e09a06e2fb97cf714f242181012701209383ab6416fcc0bfa206ce5b278abcdef216e4d3e41bbb9463a265b537091f2
|
data/lib/file-digests.rb
CHANGED
@@ -9,11 +9,13 @@ require 'sqlite3'
|
|
9
9
|
|
10
10
|
class FileDigests
|
11
11
|
DIGEST_ALGORITHMS=["BLAKE2b512", "SHA3-256", "SHA512-256"]
|
12
|
+
LEGACY_DIGEST_ALGORITHMS = ["SHA512", "SHA256"]
|
12
13
|
|
13
14
|
def self.canonical_digest_algorithm_name(string)
|
14
15
|
if string
|
15
|
-
|
16
|
-
index
|
16
|
+
algorithms = DIGEST_ALGORITHMS + LEGACY_DIGEST_ALGORITHMS
|
17
|
+
index = algorithms.map(&:downcase).index(string.downcase)
|
18
|
+
index && algorithms[index]
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
@@ -27,14 +29,14 @@ class FileDigests
|
|
27
29
|
|
28
30
|
def self.parse_cli_options
|
29
31
|
options = {}
|
30
|
-
|
32
|
+
|
31
33
|
OptionParser.new do |opts|
|
32
34
|
opts.banner = [
|
33
35
|
"Usage: file-digests [options] [path/to/directory] [path/to/database_file]",
|
34
36
|
" By default the current directory will be operated upon, and the database file will be placed to the current directory as well.",
|
35
37
|
" Should you wish to check current directory but place the database elsewhere, you could provide \".\" as a first argument, and the path to a database_file as a second."
|
36
38
|
].join "\n"
|
37
|
-
|
39
|
+
|
38
40
|
opts.on("-a", "--auto", "Do not ask for any confirmation") do
|
39
41
|
options[:auto] = true
|
40
42
|
end
|
@@ -49,8 +51,8 @@ class FileDigests
|
|
49
51
|
'Transition to a new algorithm will only occur if all files pass the check by digests which were stored using the old one.'
|
50
52
|
) do |value|
|
51
53
|
digest_algorithm = canonical_digest_algorithm_name(value)
|
52
|
-
unless digest_algorithm
|
53
|
-
STDERR.puts "ERROR: #{digest_algorithms_list_text}"
|
54
|
+
unless DIGEST_ALGORITHMS.include?(digest_algorithm)
|
55
|
+
STDERR.puts "ERROR: #{digest_algorithms_list_text}"
|
54
56
|
exit 1
|
55
57
|
end
|
56
58
|
options[:digest_algorithm] = digest_algorithm
|
@@ -212,7 +214,7 @@ class FileDigests
|
|
212
214
|
end
|
213
215
|
|
214
216
|
track_renames
|
215
|
-
|
217
|
+
|
216
218
|
if any_missing_files?
|
217
219
|
if any_exceptions?
|
218
220
|
STDERR.puts "Due to previously occurred errors, database cleanup from missing files will be skipped this time."
|
@@ -370,7 +372,7 @@ class FileDigests
|
|
370
372
|
@db.execute *args, &block
|
371
373
|
end
|
372
374
|
|
373
|
-
def nested_transaction(mode)
|
375
|
+
def nested_transaction(mode = :deferred)
|
374
376
|
if @db.transaction_active?
|
375
377
|
yield
|
376
378
|
else
|
@@ -380,9 +382,9 @@ class FileDigests
|
|
380
382
|
end
|
381
383
|
end
|
382
384
|
|
383
|
-
def perhaps_transaction(condition, mode)
|
385
|
+
def perhaps_transaction(condition, mode = :deferred)
|
384
386
|
if condition
|
385
|
-
|
387
|
+
nested_transaction(mode) do
|
386
388
|
yield
|
387
389
|
end
|
388
390
|
else
|