file-digests 0.0.34 → 0.0.39
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 +78 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac950f13dc01dc9df2f54f3ef0f5141b778b96e4bb3619859e88617561995d38
|
4
|
+
data.tar.gz: 90a54bcfdd87c28f831fe7675f8285131b01aabc1dca87c3446089ed20530bf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eac04858364ea73a555d2c1b272acca9cb78901b68b2b3dfef659f27f7b83d14c9c37a7d66f892117a7ee13aee321f2873f4f11e4cae652d09d02c3510144086
|
7
|
+
data.tar.gz: 385350fae26d40df014c9409d7fafa50fa6e10c2951c44c740e0e41ad547fe4d7f548245f97736850c796a01a0517d591a1431dfd9b6e7511d2d854d1e60979c
|
data/lib/file-digests.rb
CHANGED
@@ -140,13 +140,15 @@ class FileDigests
|
|
140
140
|
|
141
141
|
def initialize_paths files_path, digest_database_path
|
142
142
|
@files_path = cleanup_path(files_path || ".")
|
143
|
+
raise "ERROR: Files path must be a readable directory" unless (File.directory?(@files_path) && File.readable?(@files_path))
|
144
|
+
@files_path = realpath_with_disk @files_path
|
143
145
|
|
144
|
-
|
146
|
+
@error_log_path = @files_path + "file-digests errors #{Time.now.strftime("%Y-%m-%d %H-%M-%S")}.txt"
|
145
147
|
|
146
148
|
@digest_database_path = digest_database_path ? cleanup_path(digest_database_path) : @files_path
|
147
149
|
@digest_database_path += ".file-digests.sqlite" if File.directory?(@digest_database_path)
|
148
150
|
ensure_dir_exist @digest_database_path.dirname
|
149
|
-
|
151
|
+
@digest_database_path = realdirpath_with_disk @digest_database_path
|
150
152
|
@digest_database_files = ["#{@digest_database_path}", "#{@digest_database_path}-wal", "#{@digest_database_path}-shm"]
|
151
153
|
|
152
154
|
if @options[:verbose]
|
@@ -273,7 +275,7 @@ class FileDigests
|
|
273
275
|
perhaps_transaction(@new_digest_algorithm, :exclusive) do
|
274
276
|
@counters = {good: 0, updated: 0, renamed: 0, likely_damaged: 0, exceptions: 0}
|
275
277
|
|
276
|
-
walk_files do |filename|
|
278
|
+
walk_files(@files_path.to_s) do |filename|
|
277
279
|
process_file filename
|
278
280
|
end
|
279
281
|
|
@@ -340,9 +342,11 @@ class FileDigests
|
|
340
342
|
private
|
341
343
|
|
342
344
|
def process_file filename
|
343
|
-
|
345
|
+
perhaps_nt_filename = perhaps_nt_path filename
|
346
|
+
|
347
|
+
return if File.symlink? perhaps_nt_filename
|
344
348
|
|
345
|
-
stat = File.stat
|
349
|
+
stat = File.stat perhaps_nt_filename
|
346
350
|
|
347
351
|
return if stat.blockdev?
|
348
352
|
return if stat.chardev?
|
@@ -359,7 +363,7 @@ class FileDigests
|
|
359
363
|
|
360
364
|
normalized_filename = filename.delete_prefix("#{@files_path.to_s}/").encode("utf-8", universal_newline: true).unicode_normalize(:nfkc)
|
361
365
|
mtime_string = time_to_database stat.mtime
|
362
|
-
digest, new_digest = get_file_digest(
|
366
|
+
digest, new_digest = get_file_digest(perhaps_nt_filename)
|
363
367
|
|
364
368
|
nested_transaction do
|
365
369
|
new_digests_insert(normalized_filename, new_digest) if new_digest
|
@@ -368,7 +372,7 @@ class FileDigests
|
|
368
372
|
|
369
373
|
rescue => exception
|
370
374
|
@counters[:exceptions] += 1
|
371
|
-
|
375
|
+
report_file_exception exception, filename
|
372
376
|
end
|
373
377
|
|
374
378
|
def process_file_indeed filename, mtime, digest
|
@@ -394,7 +398,7 @@ class FileDigests
|
|
394
398
|
else
|
395
399
|
if found["mtime"] == mtime && !@options[:accept_fate] # Digest is different and mtime is the same
|
396
400
|
@counters[:likely_damaged] += 1
|
397
|
-
|
401
|
+
error_text "LIKELY DAMAGED: #{filename}"
|
398
402
|
else
|
399
403
|
@counters[:updated] += 1
|
400
404
|
puts "UPDATED#{" (FATE ACCEPTED)" if found["mtime"] == mtime && @options[:accept_fate]}: #{filename}" unless @options[:quiet]
|
@@ -452,6 +456,7 @@ class FileDigests
|
|
452
456
|
end
|
453
457
|
|
454
458
|
def integrity_check
|
459
|
+
puts "Checking database integrity..." if @options[:verbose]
|
455
460
|
if execute("PRAGMA integrity_check")&.first&.fetch("integrity_check") != "ok"
|
456
461
|
raise "Database integrity check failed"
|
457
462
|
end
|
@@ -529,7 +534,7 @@ class FileDigests
|
|
529
534
|
def check_if_database_is_at_certain_version target_version
|
530
535
|
current_version = get_metadata("database_version")
|
531
536
|
if current_version != target_version
|
532
|
-
STDERR.puts "This version of file-digests (#{FileDigests::VERSION || "unknown"}) is only compartible with the database version #{target_version}. Current database version is #{current_version}. To use this database, please install appropriate version if file-digest."
|
537
|
+
STDERR.puts "ERROR: This version of file-digests (#{FileDigests::VERSION || "unknown"}) is only compartible with the database version #{target_version}. Current database version is #{current_version}. To use this database, please install appropriate version if file-digest."
|
533
538
|
raise "Incompatible database version"
|
534
539
|
end
|
535
540
|
end
|
@@ -541,6 +546,22 @@ class FileDigests
|
|
541
546
|
|
542
547
|
# Filesystem-related helpers
|
543
548
|
|
549
|
+
def realpath_with_disk path
|
550
|
+
path = path.realpath
|
551
|
+
if Gem.win_platform? && path.to_s[0] == "/"
|
552
|
+
return Pathname(Dir.pwd[0, 2] + path.to_s)
|
553
|
+
end
|
554
|
+
path
|
555
|
+
end
|
556
|
+
|
557
|
+
def realdirpath_with_disk path
|
558
|
+
path = path.realdirpath
|
559
|
+
if Gem.win_platform? && path.to_s[0] == "/"
|
560
|
+
return Pathname(Dir.pwd[0, 2] + path.to_s)
|
561
|
+
end
|
562
|
+
path
|
563
|
+
end
|
564
|
+
|
544
565
|
def patch_path_string path
|
545
566
|
Gem.win_platform? ? path.gsub(/\\/, "/") : path
|
546
567
|
end
|
@@ -559,10 +580,32 @@ class FileDigests
|
|
559
580
|
end
|
560
581
|
end
|
561
582
|
|
562
|
-
def walk_files
|
563
|
-
|
564
|
-
|
565
|
-
|
583
|
+
def walk_files(path, &block)
|
584
|
+
Dir.each_child(path, encoding: "UTF-8") do |item|
|
585
|
+
item = "#{path}#{File::SEPARATOR}#{item}"
|
586
|
+
item_perhaps_nt_path = perhaps_nt_path item
|
587
|
+
|
588
|
+
unless File.symlink? item_perhaps_nt_path
|
589
|
+
if File.directory?(item_perhaps_nt_path)
|
590
|
+
if File.readable?(item_perhaps_nt_path)
|
591
|
+
walk_files(item, &block)
|
592
|
+
else
|
593
|
+
error_text "ERROR: Directory is not readable: #{item}"
|
594
|
+
@counters[:exceptions] += 1
|
595
|
+
end
|
596
|
+
else
|
597
|
+
yield item
|
598
|
+
end
|
599
|
+
end
|
600
|
+
|
601
|
+
end
|
602
|
+
end
|
603
|
+
|
604
|
+
def perhaps_nt_path path
|
605
|
+
if Gem.win_platform?
|
606
|
+
"\\??\\#{path.gsub(/\//,"\\")}"
|
607
|
+
else
|
608
|
+
path
|
566
609
|
end
|
567
610
|
end
|
568
611
|
|
@@ -610,17 +653,31 @@ class FileDigests
|
|
610
653
|
puts "Elapsed time: #{elapsed.to_i / 3600}h #{(elapsed.to_i % 3600) / 60}m #{"%.3f" % (elapsed % 60)}s" unless @options[:quiet]
|
611
654
|
end
|
612
655
|
|
613
|
-
def
|
614
|
-
STDERR
|
656
|
+
def report_file_exception exception, filename
|
657
|
+
write_file_exception STDERR, exception, filename
|
658
|
+
File.open(@error_log_path, "a") do |f|
|
659
|
+
write_file_exception f, exception, filename
|
660
|
+
end
|
661
|
+
end
|
662
|
+
|
663
|
+
def write_file_exception dest, exception, filename
|
664
|
+
dest.print "ERROR: #{exception.message}, processing file: "
|
615
665
|
begin
|
616
|
-
|
666
|
+
dest.print filename.encode("utf-8", universal_newline: true)
|
617
667
|
rescue
|
618
|
-
|
619
|
-
|
668
|
+
dest.print "(Unable to encode file name to utf-8) "
|
669
|
+
dest.print filename
|
670
|
+
end
|
671
|
+
dest.print "\n"
|
672
|
+
dest.flush
|
673
|
+
exception.backtrace.each { |line| dest.puts " " + line }
|
674
|
+
end
|
675
|
+
|
676
|
+
def error_text text
|
677
|
+
STDERR.puts text
|
678
|
+
File.open(@error_log_path, "a") do |f|
|
679
|
+
f.puts text
|
620
680
|
end
|
621
|
-
STDERR.print "\n"
|
622
|
-
STDERR.flush
|
623
|
-
exception.backtrace.each { |line| STDERR.puts " " + line }
|
624
681
|
end
|
625
682
|
|
626
683
|
def print_counters
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file-digests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.39
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stanislav Senotrusov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: openssl
|