fingerprint 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/fingerprint CHANGED
@@ -35,7 +35,8 @@ OPTIONS = {
35
35
  :name => "index.fingerprint",
36
36
  :extended => false,
37
37
  :checksums => Fingerprint::DEFAULT_CHECKSUMS,
38
- :lockfile => true
38
+ :lockfile => true,
39
+ :additions => false,
39
40
  }
40
41
 
41
42
  ARGV.options do |o|
@@ -66,12 +67,29 @@ ARGV.options do |o|
66
67
  end
67
68
 
68
69
  o.separator ""
69
- o.separator "Low level operations:"
70
+
71
+ o.on("-x", "Include additional extended information about files and directories.") do
72
+ OPTIONS[:extended] = true
73
+ end
74
+
75
+ o.on("-s [checksum1,checksum2]", "Provide a list of the checksum algorithms to use.", "Available: #{Fingerprint::CHECKSUMS.keys.join(', ')}; Default: #{OPTIONS[:checksums].join(', ')}") do |checksums|
76
+ OPTIONS[:checksums] = checksums.split(/[\s,]+/)
77
+ end
78
+
79
+ o.separator ""
80
+ o.separator "Compare fingerprints:"
70
81
 
71
82
  o.on("-c", "Compare the given fingerprints. Check that the second fingerprint is a superset of the first.") do
72
83
  OPTIONS[:mode] = :check
73
84
  end
74
85
 
86
+ o.on("-A", "Report files that have been added to the second fingerprint.") do
87
+ OPTIONS[:additions] = true
88
+ end
89
+
90
+ o.separator ""
91
+ o.separator "Output manipulation:"
92
+
75
93
  o.on("-o [output-path]", String, "Write the fingerprint output to the given file.") do |path|
76
94
  OPTIONS[:output] = File.open(path, "w")
77
95
  end
@@ -87,16 +105,6 @@ ARGV.options do |o|
87
105
  o.on("--no-lockfile", "Don't use a lockfile to validate access to the fingerprint.") do
88
106
  OPTIONS[:lockfile] = false
89
107
  end
90
-
91
- o.separator ""
92
-
93
- o.on("-x", "Include additional extended information about files and directories.") do
94
- OPTIONS[:extended] = true
95
- end
96
-
97
- o.on("-s [checksum1,checksum2]", "Provide a list of the checksum algorithms to use.", "Available: #{Fingerprint::CHECKSUMS.keys.join(', ')}; Default: #{OPTIONS[:checksums].join(', ')}") do |checksums|
98
- OPTIONS[:checksums] = checksums.split(/[\s,]+/)
99
- end
100
108
 
101
109
  o.separator ""
102
110
  o.separator "Help and Copyright information:"
@@ -42,7 +42,7 @@ module Fingerprint
42
42
  attr :copy
43
43
 
44
44
  # Run the checking process.
45
- def check (options = {}, &block)
45
+ def check (&block)
46
46
  # For every file in the src, we check that it exists
47
47
  # in the destination:
48
48
 
@@ -50,7 +50,15 @@ module Fingerprint
50
50
  processed_size = 0
51
51
  total_size = @master.records.inject(0) { |count, record| count + (record['file.size'] || 0).to_i }
52
52
 
53
+ if @options[:additions]
54
+ copy_paths = @copy.paths.dup
55
+ else
56
+ copy_paths = {}
57
+ end
58
+
53
59
  @master.records.each_with_index do |record, processed_count|
60
+ copy_paths.delete(record.path)
61
+
54
62
  next if record.mode != :file
55
63
 
56
64
  result, message = @copy.compare(record)
@@ -71,6 +79,12 @@ module Fingerprint
71
79
  processed_size += (record['file.size'] || 0).to_i
72
80
  end
73
81
  end
82
+
83
+ if @options[:additions]
84
+ copy_paths.each do |path, record|
85
+ yield record, :addition, "File #{path} added."
86
+ end
87
+ end
74
88
  end
75
89
 
76
90
  # A list of files which either did not exist in the copy, or had the wrong checksum.
@@ -105,14 +119,17 @@ module Fingerprint
105
119
 
106
120
  checker.check do |record, result, message|
107
121
  error_count += 1
108
- copy = checker.copy.paths[record.path]
109
122
 
110
123
  metadata = {
111
124
  'error.code' => result,
112
125
  'error.message' => message
113
126
  }
114
127
 
115
- if copy
128
+ if result == :addition
129
+ metadata.merge!(record.metadata)
130
+
131
+ errors << Record.new(:warning, record.path, metadata)
132
+ elsif (copy = checker.copy.paths[record.path])
116
133
  changes = record.diff(copy)
117
134
 
118
135
  changes.each do |name|
@@ -126,7 +143,13 @@ module Fingerprint
126
143
  end
127
144
  end
128
145
 
129
- errors << Record.new(:summary, nil, {
146
+ if error_count
147
+ summary_message = "#{error_count} error(s) detected."
148
+ else
149
+ summary_message = "No errors detected"
150
+ end
151
+
152
+ errors << Record.new(:summary, summary_message, {
130
153
  'error.count' => error_count
131
154
  })
132
155
 
@@ -67,7 +67,7 @@ module Fingerprint
67
67
  options = {}
68
68
 
69
69
  options[:extended] = true if @metadata['options.extended'] == 'true'
70
- options[:checksum] = @metadata['options.checksums'].split(/[\s,]+/) if @metadata['options.checksums']
70
+ options[:checksums] = @metadata['options.checksums'].split(/[\s,]+/) if @metadata['options.checksums']
71
71
 
72
72
  return options
73
73
  end
@@ -264,9 +264,11 @@ module Fingerprint
264
264
  end
265
265
  end
266
266
  end
267
+
268
+ summary_message = "#{processed_count} files processed."
267
269
 
268
270
  # Output summary
269
- recordset << Record.new(:summary, nil, {
271
+ recordset << Record.new(:summary, summary_message, {
270
272
  'summary.directories' => directory_count,
271
273
  'summary.files' => processed_count,
272
274
  'summary.size' => processed_size,
@@ -23,7 +23,7 @@ module Fingerprint
23
23
  module VERSION
24
24
  MAJOR = 1
25
25
  MINOR = 3
26
- TINY = 1
26
+ TINY = 2
27
27
 
28
28
  STRING = [MAJOR, MINOR, TINY].join('.')
29
29
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fingerprint
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 1
10
- version: 1.3.1
9
+ - 2
10
+ version: 1.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Samuel Williams
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-05 00:00:00 Z
18
+ date: 2011-10-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: lockfile