fingerprint 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8ad0fb2f50f482dc7dc06185001d5eefd60ea136069d0e0c2004eaefdba4351
4
- data.tar.gz: a0256e102d7628d5410fa94bb9f23b8f0858155a10d4dbef108097b76129ec78
3
+ metadata.gz: fe183e59d36938796040005023943811697ab7c5f4d18c78f4740dd21bdcacb5
4
+ data.tar.gz: a781c31d0eb206bf505ca521331e13681b43014a15260c7a6aeb6cf7056796c0
5
5
  SHA512:
6
- metadata.gz: d0aff09d12a3c2f5c683433aa1e6ed0f9f2a8d77be668cdd1aac6d20899821d091f1edce2be721bc5889b12cfe69bfd1248fed6e275ab6a941c7da6b416d2457
7
- data.tar.gz: 1ac6617e297ed4395fb05fd8cb6e785f98b9f298b0b1326235b034d450c78858cdbcab7370b781150c8acc06ff6cb7df444703632321374d426a02dfaf0f14c7
6
+ metadata.gz: 9fea4f8529180e152013a160c8e87f7deb046cd7270a2f9b4206ecb9ff84454f6fccedd93b98488cfc79baf9b33c9dcd863ce7fd586cd12da29d56203f59c31a
7
+ data.tar.gz: db95df8fbbf8b5d67a0bfe68d3953d8066c549d055c772d15705f3b54e2bf7c2f555e854335694da3ec27347e0c1d50835a3c0871b16656ca229eff70232b479
checksums.yaml.gz.sig CHANGED
Binary file
@@ -98,17 +98,10 @@ module Fingerprint
98
98
  def self.check_files(master, copy, **options, &block)
99
99
  # New API that takes two RecordSets...
100
100
 
101
- File.open(master) do |master_file|
102
- File.open(copy) do |copy_file|
103
- master_recordset = RecordSet.new
104
- master_recordset.parse(master_file)
105
-
106
- copy_recordset = RecordSet.new
107
- copy_recordset.parse(copy_file)
108
-
109
- verify(master_recordset, copy_recordset, **options, &block)
110
- end
111
- end
101
+ master_recordset = RecordSet.load_file(master)
102
+ copy_recordset = RecordSet.load_file(copy)
103
+
104
+ verify(master_recordset, copy_recordset, **options, &block)
112
105
  end
113
106
 
114
107
  # Helper function to check two fingerprint files.
@@ -33,6 +33,8 @@ module Fingerprint
33
33
  option "-i/--inverse", "Invert the output, i.e. show files which are not duplicates."
34
34
  option "-x/--extended", "Include extended information about files and directories."
35
35
 
36
+ option "--delete", "Delete duplicates."
37
+
36
38
  option "--verbose", "Verbose output, e.g. what is happening."
37
39
  end
38
40
 
@@ -41,56 +43,57 @@ module Fingerprint
41
43
 
42
44
  attr :duplicates_recordset
43
45
 
46
+ def delete(path)
47
+ FileUtils.rm_f(path)
48
+ end
49
+
44
50
  def call
45
51
  @duplicates_recordset = RecordSet.new
46
52
  results = RecordSetPrinter.new(@duplicates_recordset, @parent.output)
47
53
 
48
54
  master_file_path = @master
49
- File.open(master_file_path) do |master_file|
50
- master_recordset = RecordSet.new
51
- master_recordset.parse(master_file)
55
+ master_recordset = RecordSet.load_file(master_file_path)
52
56
 
53
- ignore_similar = false
54
-
55
- copy_file_paths = @copies
56
-
57
- if copy_file_paths.size == 0
58
- copy_file_paths = [master_file_path]
59
- ignore_similar = true
60
- end
57
+ ignore_similar = false
58
+
59
+ copy_file_paths = @copies
60
+
61
+ if copy_file_paths.size == 0
62
+ copy_file_paths = [master_file_path]
63
+ ignore_similar = true
64
+ end
65
+
66
+ copy_file_paths.each do |copy_file_path|
67
+ copy_recordset = RecordSet.load_file(copy_file_path)
61
68
 
62
- copy_file_paths.each do |copy_file_path|
63
- File.open(copy_file_path) do |copy_file|
64
- copy_recordset = RecordSet.new
65
- copy_recordset.parse(copy_file)
69
+ copy_recordset.records.each do |record|
70
+ next unless record.file?
71
+
72
+ record.metadata['fingerprint'] = copy_file_path
73
+
74
+ # We need to see if the record exists in the master
75
+
76
+ if @options[:verbose]
77
+ $stderr.puts "Checking #{record.inspect}"
78
+ end
79
+
80
+ main_record = master_recordset.find_by_key(record)
81
+
82
+ # If we are scanning the same index, don't print out every file, just those that are duplicates within the single file.
83
+ if ignore_similar && main_record && (main_record.path == record.path)
84
+ main_record = nil
85
+ end
86
+
87
+ if main_record
88
+ record.metadata['original.path'] = main_record.path
89
+ record.metadata['original.fingerprint'] = master_file_path
90
+ results << record if !@options[:inverse]
66
91
 
67
- copy_recordset.records.each do |record|
68
- next unless record.file?
69
-
70
- record.metadata['fingerprint'] = copy_file_path
71
- record.metadata['full_path'] = copy_recordset.full_path(record.path)
72
-
73
- # We need to see if the record exists in the master
74
-
75
- if @options[:verbose]
76
- $stderr.puts "Checking #{record.inspect}"
77
- end
78
-
79
- main_record = master_recordset.find_by_key(record)
80
-
81
- # If we are scanning the same index, don't print out every file, just those that are duplicates within the single file.
82
- if ignore_similar && main_record && (main_record.path == record.path)
83
- main_record = nil
84
- end
85
-
86
- if main_record
87
- record.metadata['original.path'] = main_record.path
88
- record.metadata['original.fingerprint'] = master_file_path
89
- results << record if !@options[:inverse]
90
- else
91
- results << record if @options[:inverse]
92
- end
92
+ if @options[:delete]
93
+ delete(copy_recordset.full_path(record.path))
93
94
  end
95
+ else
96
+ results << record if @options[:inverse]
94
97
  end
95
98
  end
96
99
  end
@@ -60,11 +60,7 @@ module Fingerprint
60
60
  options = @options.dup
61
61
  options[:output] = @parent.output
62
62
 
63
- master = RecordSet.new
64
-
65
- File.open(input_file, "r") do |io|
66
- master.parse(io)
67
- end
63
+ master = RecordSet.load_file(input_file)
68
64
 
69
65
  if master.configuration
70
66
  options.merge!(master.configuration.options)
@@ -90,13 +90,16 @@ module Fingerprint
90
90
 
91
91
  class RecordSet
92
92
  def self.load_file(path)
93
+ path = File.expand_path(path)
94
+ root = File.dirname(path)
95
+
96
+ record_set = self.new(root)
97
+
93
98
  File.open(path, "r") do |io|
94
- self.load(io)
99
+ record_set.parse(io)
95
100
  end
96
- end
97
-
98
- def self.load(io)
99
- self.new.tap{|record_set| record_set.parse(io)}
101
+
102
+ return record_set
100
103
  end
101
104
 
102
105
  def initialize(root = nil)
@@ -131,7 +134,7 @@ module Fingerprint
131
134
  end
132
135
 
133
136
  @configuration = record
134
- @root = @configuration.path
137
+ @root ||= @configuration.path
135
138
  else
136
139
  @paths[record.path] = record
137
140
 
@@ -239,7 +242,7 @@ module Fingerprint
239
242
  elsif line.match(/^\s+([a-zA-Z\.0-9]+)\s+(.*)$/)
240
243
  metadata[$1] = $2
241
244
  else
242
- $stderr.puts "Unhandled line: #{line}"
245
+ raise "Unhandled line: #{line}"
243
246
  end
244
247
  end
245
248
 
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Fingerprint
22
- VERSION = "3.3.0"
22
+ VERSION = "3.4.0"
23
23
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fingerprint
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file