file-digests 0.0.37 → 0.0.38

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 +46 -10
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27e992f2a4849569d6c87e53807ebdc53676b3e47ca2c1efd2799927fd16d0c7
4
- data.tar.gz: 9e292709b7978d906b0423a980cc72b23f8a44c665f070d71f30953ccdc59256
3
+ metadata.gz: 1a7193a9795eb785cd22a7663fa4dae908d3349b854be8d3613750f24ce6b711
4
+ data.tar.gz: 32a8172cc7115240f5954b7e4775f841ddce10102c7e48e184690d2643e7a476
5
5
  SHA512:
6
- metadata.gz: c80f844d16255d9437c8dd012eff010df23f5a14d87336bf987b34e913a12fa0932fd85e18760884c63d10f882041afecf77b0b354555cef62aadc98de5ba091
7
- data.tar.gz: f5f5c8309b8921f034edeb36643cab34dff52e4091cd5508462294a48e79002dfdbdf09a126988449d1775d207651579ca19ffb7cd169038fe71067dabb5b8af
6
+ metadata.gz: 584a6fc4c10e6a33d9e55d9647abcfce913fa18b046eddf7193807408d7ac4167b1b7114aa300531426e767668841f483ad66775bf7f492ff552f290d19f6e2a
7
+ data.tar.gz: 877dea6a6ba8f3ab091ed6d5b0379090a60cff4477ad9d4409fa9fef9674bd39b9134682ac534d49535a21ed58382b02088fa00f83524d31add7c23919e9c0c4
@@ -140,13 +140,13 @@ class FileDigests
140
140
 
141
141
  def initialize_paths files_path, digest_database_path
142
142
  @files_path = cleanup_path(files_path || ".")
143
-
144
143
  raise "Files path must be a readable directory" unless (File.directory?(@files_path) && File.readable?(@files_path))
144
+ @files_path = realpath_with_disk @files_path
145
145
 
146
146
  @digest_database_path = digest_database_path ? cleanup_path(digest_database_path) : @files_path
147
147
  @digest_database_path += ".file-digests.sqlite" if File.directory?(@digest_database_path)
148
148
  ensure_dir_exist @digest_database_path.dirname
149
-
149
+ @digest_database_path = realdirpath_with_disk @digest_database_path
150
150
  @digest_database_files = ["#{@digest_database_path}", "#{@digest_database_path}-wal", "#{@digest_database_path}-shm"]
151
151
 
152
152
  if @options[:verbose]
@@ -273,7 +273,7 @@ class FileDigests
273
273
  perhaps_transaction(@new_digest_algorithm, :exclusive) do
274
274
  @counters = {good: 0, updated: 0, renamed: 0, likely_damaged: 0, exceptions: 0}
275
275
 
276
- walk_files do |filename|
276
+ walk_files(@files_path.to_s) do |filename|
277
277
  process_file filename
278
278
  end
279
279
 
@@ -340,9 +340,11 @@ class FileDigests
340
340
  private
341
341
 
342
342
  def process_file filename
343
- return if File.symlink? filename
343
+ perhaps_nt_filename = perhaps_nt_path filename
344
+
345
+ return if File.symlink? perhaps_nt_filename
344
346
 
345
- stat = File.stat filename
347
+ stat = File.stat perhaps_nt_filename
346
348
 
347
349
  return if stat.blockdev?
348
350
  return if stat.chardev?
@@ -359,7 +361,7 @@ class FileDigests
359
361
 
360
362
  normalized_filename = filename.delete_prefix("#{@files_path.to_s}/").encode("utf-8", universal_newline: true).unicode_normalize(:nfkc)
361
363
  mtime_string = time_to_database stat.mtime
362
- digest, new_digest = get_file_digest(filename)
364
+ digest, new_digest = get_file_digest(perhaps_nt_filename)
363
365
 
364
366
  nested_transaction do
365
367
  new_digests_insert(normalized_filename, new_digest) if new_digest
@@ -542,6 +544,22 @@ class FileDigests
542
544
 
543
545
  # Filesystem-related helpers
544
546
 
547
+ def realpath_with_disk path
548
+ path = path.realpath
549
+ if Gem.win_platform? && path.to_s[0] == "/"
550
+ return Pathname(Dir.pwd[0, 2] + path.to_s)
551
+ end
552
+ path
553
+ end
554
+
555
+ def realdirpath_with_disk path
556
+ path = path.realdirpath
557
+ if Gem.win_platform? && path.to_s[0] == "/"
558
+ return Pathname(Dir.pwd[0, 2] + path.to_s)
559
+ end
560
+ path
561
+ end
562
+
545
563
  def patch_path_string path
546
564
  Gem.win_platform? ? path.gsub(/\\/, "/") : path
547
565
  end
@@ -560,10 +578,28 @@ class FileDigests
560
578
  end
561
579
  end
562
580
 
563
- def walk_files
564
- puts "Gathering the list of files..." if @options[:verbose]
565
- Dir.glob(@files_path + "**" + "*", File::FNM_DOTMATCH) do |filename|
566
- yield filename
581
+ def walk_files(path, &block)
582
+ Dir.each_child(path, encoding: "UTF-8") do |item|
583
+ 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)
588
+ else
589
+ yield item
590
+ end
591
+ else
592
+ STDERR.puts "ERROR: Directory entry is not readable: #{item}"
593
+ @counters[:exceptions] += 1
594
+ end
595
+ end
596
+ end
597
+
598
+ def perhaps_nt_path path
599
+ if Gem.win_platform?
600
+ "\\??\\#{path.gsub(/\//,"\\")}"
601
+ else
602
+ path
567
603
  end
568
604
  end
569
605
 
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.37
4
+ version: 0.0.38
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-17 00:00:00.000000000 Z
11
+ date: 2020-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openssl