file-digests 0.0.38 → 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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/file-digests.rb +39 -19
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a7193a9795eb785cd22a7663fa4dae908d3349b854be8d3613750f24ce6b711
4
- data.tar.gz: 32a8172cc7115240f5954b7e4775f841ddce10102c7e48e184690d2643e7a476
3
+ metadata.gz: ac950f13dc01dc9df2f54f3ef0f5141b778b96e4bb3619859e88617561995d38
4
+ data.tar.gz: 90a54bcfdd87c28f831fe7675f8285131b01aabc1dca87c3446089ed20530bf5
5
5
  SHA512:
6
- metadata.gz: 584a6fc4c10e6a33d9e55d9647abcfce913fa18b046eddf7193807408d7ac4167b1b7114aa300531426e767668841f483ad66775bf7f492ff552f290d19f6e2a
7
- data.tar.gz: 877dea6a6ba8f3ab091ed6d5b0379090a60cff4477ad9d4409fa9fef9674bd39b9134682ac534d49535a21ed58382b02088fa00f83524d31add7c23919e9c0c4
6
+ metadata.gz: eac04858364ea73a555d2c1b272acca9cb78901b68b2b3dfef659f27f7b83d14c9c37a7d66f892117a7ee13aee321f2873f4f11e4cae652d09d02c3510144086
7
+ data.tar.gz: 385350fae26d40df014c9409d7fafa50fa6e10c2951c44c740e0e41ad547fe4d7f548245f97736850c796a01a0517d591a1431dfd9b6e7511d2d854d1e60979c
@@ -140,9 +140,11 @@ class FileDigests
140
140
 
141
141
  def initialize_paths files_path, digest_database_path
142
142
  @files_path = cleanup_path(files_path || ".")
143
- raise "Files path must be a readable directory" unless (File.directory?(@files_path) && File.readable?(@files_path))
143
+ raise "ERROR: Files path must be a readable directory" unless (File.directory?(@files_path) && File.readable?(@files_path))
144
144
  @files_path = realpath_with_disk @files_path
145
145
 
146
+ @error_log_path = @files_path + "file-digests errors #{Time.now.strftime("%Y-%m-%d %H-%M-%S")}.txt"
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
@@ -370,7 +372,7 @@ class FileDigests
370
372
 
371
373
  rescue => exception
372
374
  @counters[:exceptions] += 1
373
- print_file_exception exception, filename
375
+ report_file_exception exception, filename
374
376
  end
375
377
 
376
378
  def process_file_indeed filename, mtime, digest
@@ -396,7 +398,7 @@ class FileDigests
396
398
  else
397
399
  if found["mtime"] == mtime && !@options[:accept_fate] # Digest is different and mtime is the same
398
400
  @counters[:likely_damaged] += 1
399
- STDERR.puts "LIKELY DAMAGED: #{filename}"
401
+ error_text "LIKELY DAMAGED: #{filename}"
400
402
  else
401
403
  @counters[:updated] += 1
402
404
  puts "UPDATED#{" (FATE ACCEPTED)" if found["mtime"] == mtime && @options[:accept_fate]}: #{filename}" unless @options[:quiet]
@@ -532,7 +534,7 @@ class FileDigests
532
534
  def check_if_database_is_at_certain_version target_version
533
535
  current_version = get_metadata("database_version")
534
536
  if current_version != target_version
535
- 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."
536
538
  raise "Incompatible database version"
537
539
  end
538
540
  end
@@ -581,17 +583,21 @@ class FileDigests
581
583
  def walk_files(path, &block)
582
584
  Dir.each_child(path, encoding: "UTF-8") do |item|
583
585
  item = "#{path}#{File::SEPARATOR}#{item}"
584
- test_item = perhaps_nt_path item
585
- if File.readable?(test_item)
586
- if File.directory?(test_item)
587
- walk_files(item, &block)
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
588
596
  else
589
597
  yield item
590
598
  end
591
- else
592
- STDERR.puts "ERROR: Directory entry is not readable: #{item}"
593
- @counters[:exceptions] += 1
594
599
  end
600
+
595
601
  end
596
602
  end
597
603
 
@@ -647,17 +653,31 @@ class FileDigests
647
653
  puts "Elapsed time: #{elapsed.to_i / 3600}h #{(elapsed.to_i % 3600) / 60}m #{"%.3f" % (elapsed % 60)}s" unless @options[:quiet]
648
654
  end
649
655
 
650
- def print_file_exception exception, filename
651
- STDERR.print "EXCEPTION: #{exception.message}, processing file: "
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: "
652
665
  begin
653
- STDERR.print filename.encode("utf-8", universal_newline: true)
666
+ dest.print filename.encode("utf-8", universal_newline: true)
654
667
  rescue
655
- STDERR.print "(Unable to encode file name to utf-8) "
656
- STDERR.print filename
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
657
680
  end
658
- STDERR.print "\n"
659
- STDERR.flush
660
- exception.backtrace.each { |line| STDERR.puts " " + line }
661
681
  end
662
682
 
663
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.38
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-18 00:00:00.000000000 Z
11
+ date: 2020-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openssl