fingerprint 1.4.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'fingerprint/command'
24
+
25
+ require_relative 'source_fingerprint'
26
+
27
+ RSpec.describe Fingerprint::Command::Verify do
28
+ include_context "source fingerprint"
29
+
30
+ it "should analyze a different path" do
31
+ Fingerprint::Command::Top["analyze", "-n", fingerprint_name, "-f", source_directory].call
32
+
33
+ expect(File).to be_exist(fingerprint_name)
34
+
35
+ top = Fingerprint::Command::Top["verify", "-n", fingerprint_name, "-f", source_directory].tap(&:call)
36
+
37
+ expect(top.command.error_count).to be == 0
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ # Corpus
2
+
3
+ This directory contains some sample files.
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'fingerprint/scanner'
24
+
25
+ RSpec.shared_examples "scanner checksum" do |digests|
26
+ let(:scanner) {Fingerprint::Scanner.new([__dir__], checksums: subject)}
27
+
28
+ it "computes checksums correctly" do
29
+ digests.each do |path, required_metadata|
30
+ record = scanner.scan_path(path)
31
+
32
+ expect(record.metadata).to include(required_metadata)
33
+ end
34
+ end
35
+ end
36
+
37
+ RSpec.describe "defaults" do
38
+ it "defaults to SHA2.256 only" do
39
+ expect(Fingerprint::DEFAULT_CHECKSUMS).to eq(['SHA2.256'])
40
+ end
41
+ end
42
+
43
+ RSpec.describe ['MD5'] do
44
+ it_behaves_like "scanner checksum",
45
+ "corpus/README.md" => {
46
+ "file.size" => 52,
47
+ "key.MD5" => "2d7157522d94e7d1621daefd5b92817f",
48
+ }
49
+ end
50
+
51
+ RSpec.describe ['SHA1'] do
52
+ it_behaves_like "scanner checksum",
53
+ "corpus/README.md" => {
54
+ "file.size" => 52,
55
+ "key.SHA1" => "a36492a961d2672efc481059860af5c1dd9a2aed"
56
+ }
57
+ end
58
+
59
+ RSpec.describe ['SHA2.256', 'SHA2.384', 'SHA2.512'] do
60
+ it_behaves_like "scanner checksum",
61
+ "corpus/README.md" => {
62
+ "file.size" => 52,
63
+ "key.SHA2.256" => "0d991d01d74c50cd5dcce8140e61e4da5a06e468d9df704195e84863269ce20f",
64
+ "key.SHA2.384" => "8d9b81d6aa761b9611dbcb76471e667854ece77a134aa53953651938e233791fe6a4b6aa2db3eb7b9531bdb49ce5a31f",
65
+ "key.SHA2.512" => "73c9d10f92ca7a0d53641efe59860a7bd358185cfe5ba51fe7b19a6894344f3109de8840d3ae73742c5a059daffcbdda865111f1925604e3f6c59d33443bde2c",
66
+ }
67
+ end
@@ -1,6 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env rspec
2
2
 
3
- # Copyright (c) 2007, 2011 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
3
+ # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the "Software"), to deal
@@ -20,42 +20,14 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- require 'rubygems'
24
-
25
- require 'test/unit'
26
- require 'fileutils'
27
- require 'pathname'
28
23
  require 'fingerprint'
29
24
 
30
- require 'timeout'
31
-
32
- class TestFingerprint < Test::Unit::TestCase
33
- def test_analyze_verify
34
- File.open("junk.txt", "w") { |fp| fp.write("foobar") }
35
-
36
- result = system("fingerprint --analyze ./ -f")
37
-
38
- File.open("junk.txt", "w") { |fp| fp.write("foobar") }
39
-
40
- result = system("fingerprint --verify ./")
41
-
42
- assert_equal true, result
43
-
44
- File.open("junk.txt", "w") { |fp| fp.write("foobaz") }
45
-
46
- result = system("fingerprint -X --verify ./")
47
-
48
- assert_equal false, result
25
+ describe Fingerprint do
26
+ it "should check the same path and not report any differences" do
27
+ expect(Fingerprint).to be_identical(__dir__, __dir__)
49
28
  end
50
-
51
- def test_check_paths
52
- errors = 0
53
- test_path = File.dirname(__FILE__)
54
-
55
- Fingerprint::check_paths(test_path, test_path) do |record, result, message|
56
- errors += 1
57
- end
58
-
59
- assert_equal errors, 0
29
+
30
+ it "should check different paths and report differences" do
31
+ expect(Fingerprint).to_not be_identical(__dir__, File.expand_path("../", __dir__))
60
32
  end
61
33
  end
@@ -0,0 +1,31 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'bundler/setup'
22
+ require 'covered/rspec'
23
+
24
+ RSpec.configure do |config|
25
+ # Enable flags like --only-failures and --next-failure
26
+ config.example_status_persistence_file_path = ".rspec_status"
27
+
28
+ config.expect_with :rspec do |c|
29
+ c.syntax = :expect
30
+ end
31
+ end
metadata CHANGED
@@ -1,55 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fingerprint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-13 00:00:00.000000000 Z
11
+ date: 2019-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: samovar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: build-files
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ~>
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.3'
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: covered
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
20
48
  type: :development
21
49
  prerelease: false
22
50
  version_requirements: !ruby/object:Gem::Requirement
23
51
  requirements:
24
- - - ~>
52
+ - - ">="
25
53
  - !ruby/object:Gem::Version
26
- version: '1.3'
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
- name: rake
56
+ name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
- - - '>='
59
+ - - ">="
32
60
  - !ruby/object:Gem::Version
33
61
  version: '0'
34
62
  type: :development
35
63
  prerelease: false
36
64
  version_requirements: !ruby/object:Gem::Requirement
37
65
  requirements:
38
- - - '>='
66
+ - - ">="
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
- name: lockfile
70
+ name: rspec
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - '>='
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
46
88
  - !ruby/object:Gem::Version
47
89
  version: '0'
48
- type: :runtime
90
+ type: :development
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
- - - '>='
94
+ - - ">="
53
95
  - !ruby/object:Gem::Version
54
96
  version: '0'
55
97
  description: "\t\tFingerprint is a general purpose data integrity tool that uses cryptographic
@@ -62,22 +104,39 @@ email:
62
104
  - samuel.williams@oriontransfer.co.nz
63
105
  executables:
64
106
  - fingerprint
65
- - fingerprint-diff
66
107
  extensions: []
67
108
  extra_rdoc_files: []
68
109
  files:
110
+ - ".gitignore"
111
+ - ".rspec"
112
+ - ".travis.yml"
113
+ - GUIDE.md
69
114
  - Gemfile
70
115
  - README.md
116
+ - Rakefile
71
117
  - bin/fingerprint
72
- - bin/fingerprint-diff
73
118
  - fingerprint.gemspec
74
119
  - lib/fingerprint.rb
75
120
  - lib/fingerprint/checker.rb
121
+ - lib/fingerprint/checksums.rb
122
+ - lib/fingerprint/command.rb
123
+ - lib/fingerprint/command/analyze.rb
124
+ - lib/fingerprint/command/compare.rb
125
+ - lib/fingerprint/command/duplicates.rb
126
+ - lib/fingerprint/command/scan.rb
127
+ - lib/fingerprint/command/verify.rb
128
+ - lib/fingerprint/find.rb
76
129
  - lib/fingerprint/record.rb
77
130
  - lib/fingerprint/scanner.rb
78
131
  - lib/fingerprint/version.rb
79
- - rakefile.rb
80
- - test/test_fingerprint.rb
132
+ - spec/fingerprint/command/analyze_spec.rb
133
+ - spec/fingerprint/command/duplicates_spec.rb
134
+ - spec/fingerprint/command/source_fingerprint.rb
135
+ - spec/fingerprint/command/verify_spec.rb
136
+ - spec/fingerprint/corpus/README.md
137
+ - spec/fingerprint/scanner_spec.rb
138
+ - spec/fingerprint_spec.rb
139
+ - spec/spec_helper.rb
81
140
  homepage: http://www.codeotaku.com/projects/fingerprint
82
141
  licenses:
83
142
  - MIT
@@ -88,20 +147,26 @@ require_paths:
88
147
  - lib
89
148
  required_ruby_version: !ruby/object:Gem::Requirement
90
149
  requirements:
91
- - - '>='
150
+ - - ">="
92
151
  - !ruby/object:Gem::Version
93
152
  version: '0'
94
153
  required_rubygems_version: !ruby/object:Gem::Requirement
95
154
  requirements:
96
- - - '>='
155
+ - - ">="
97
156
  - !ruby/object:Gem::Version
98
157
  version: '0'
99
158
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.0.6
159
+ rubygems_version: 3.0.3
102
160
  signing_key:
103
161
  specification_version: 4
104
162
  summary: Fingerprint is a tool for creating checksums of entire directory structures,
105
163
  and comparing them for inconsistencies.
106
164
  test_files:
107
- - test/test_fingerprint.rb
165
+ - spec/fingerprint/command/analyze_spec.rb
166
+ - spec/fingerprint/command/duplicates_spec.rb
167
+ - spec/fingerprint/command/source_fingerprint.rb
168
+ - spec/fingerprint/command/verify_spec.rb
169
+ - spec/fingerprint/corpus/README.md
170
+ - spec/fingerprint/scanner_spec.rb
171
+ - spec/fingerprint_spec.rb
172
+ - spec/spec_helper.rb
@@ -1,145 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright (c) 2011 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'optparse'
24
- require 'pathname'
25
- require 'fingerprint'
26
- require 'lockfile'
27
- require 'fileutils'
28
-
29
- OPTIONS = {
30
- :mode => nil,
31
- :output => $stdout,
32
- :verbose => false,
33
- :force => false,
34
- :extended => false,
35
- :inverse => false
36
- }
37
-
38
- $options = nil
39
-
40
- ARGV.options do |o|
41
- $options = o
42
-
43
- script_name = File.basename($0)
44
-
45
- o.banner = "Usage: #{script_name} [options] [path]"
46
- o.define_head "This script is used to calculate the differences between two fingerprints."
47
-
48
- o.separator ""
49
- o.separator "Set operations between fingerprints:"
50
-
51
- o.on("--duplicates", "Calculate files in copy that already exist in master") do |master, copy|
52
- OPTIONS[:mode] = :duplicates
53
- end
54
-
55
- o.separator ""
56
- o.separator "Output manipulation:"
57
-
58
- o.on("-o [output-path]", String, "Write the fingerprint output to the given file.") do |path|
59
- OPTIONS[:output] = File.open(path, "w")
60
- end
61
-
62
- o.on("--verbose", "Verbose output, include additional details in the file transcript.") do
63
- OPTIONS[:verbose] = true
64
- end
65
-
66
- o.on("--progress", "Print percentage progress to standard error.") do
67
- OPTIONS[:progress] = true
68
- end
69
-
70
- o.on("--inverse", "Show the inverse of the selected operation.") do
71
- OPTIONS[:inverse] = true
72
- end
73
-
74
- o.separator ""
75
- o.separator "Help and Copyright information:"
76
-
77
- o.on_tail("--copy", "Display copyright and warranty information") do
78
- $stderr.puts "#{script_name} v#{Fingerprint::VERSION::STRING}. Copyright (c) 2011 Samuel Williams."
79
- $stderr.puts "This software is released under the MIT license and comes with ABSOLUTELY NO WARRANTY."
80
- $stderr.puts "See http://www.oriontransfer.co.nz/ for more information."
81
- exit
82
- end
83
-
84
- o.on_tail("-h", "--help", "Show this help message.") do
85
- $stderr.puts o
86
- exit
87
- end
88
- end.parse!
89
-
90
- case (OPTIONS[:mode])
91
- when :duplicates
92
- options = OPTIONS.dup
93
-
94
- include Fingerprint
95
-
96
- duplicates_recordset = RecordSet.new
97
- results = RecordSetPrinter.new(duplicates_recordset, OPTIONS[:output])
98
-
99
- master_file_path = ARGV.shift
100
- File.open(master_file_path) do |master_file|
101
- master_recordset = RecordSet.new
102
- master_recordset.parse(master_file)
103
-
104
- ignore_similar = false
105
-
106
- copy_file_paths = ARGV
107
- if copy_file_paths.size == 0
108
- copy_file_paths = [master_file_path]
109
- ignore_similar = true
110
- end
111
-
112
- copy_file_paths.each do |copy_file_path|
113
- File.open(copy_file_path) do |copy_file|
114
- copy_recordset = RecordSet.new
115
- copy_recordset.parse(copy_file)
116
-
117
- copy_recordset.records.each do |record|
118
- record.metadata['fingerprint'] = copy_file_path
119
- # We need to see if the record exists in the master
120
-
121
- if OPTIONS[:verbose]
122
- $stderr.puts "Checking #{record.inspect}"
123
- end
124
-
125
- main_record = master_recordset.find_by_key(record)
126
-
127
- # If we are scanning the same index, don't print out every file, just those that are duplicates within the single file.
128
- if ignore_similar && main_record && (main_record.path == record.path)
129
- main_record = nil
130
- end
131
-
132
- if main_record
133
- record.metadata['original.path'] = main_record.path
134
- record.metadata['original.fingerprint'] = master_file_path
135
- results << record if !OPTIONS[:inverse]
136
- else
137
- results << record if OPTIONS[:inverse]
138
- end
139
- end
140
- end
141
- end
142
- end
143
- else
144
- puts $options
145
- end