fingerprint 1.1.3 → 1.2.0
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.
- data/bin/fingerprint +74 -5
- data/lib/fingerprint/checker.rb +8 -4
- data/lib/fingerprint/version.rb +2 -2
- metadata +4 -4
data/bin/fingerprint
CHANGED
@@ -21,13 +21,18 @@
|
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
23
|
require 'optparse'
|
24
|
+
require 'pathname'
|
24
25
|
require 'fingerprint'
|
25
26
|
|
27
|
+
FINGERPRINT_NAME = "._fingerprint"
|
28
|
+
|
26
29
|
OPTIONS = {
|
27
30
|
:root => "./",
|
28
31
|
:mode => :scan,
|
29
32
|
:output => nil,
|
30
|
-
:verbose => false
|
33
|
+
:verbose => false,
|
34
|
+
:force => false,
|
35
|
+
:name => "._fingerprint.txt"
|
31
36
|
}
|
32
37
|
|
33
38
|
ARGV.options do |o|
|
@@ -36,6 +41,30 @@ ARGV.options do |o|
|
|
36
41
|
o.banner = "Usage: #{script_name} [options] [path]"
|
37
42
|
o.define_head "This script is used to calculate and compare a basic file system fingerprint."
|
38
43
|
|
44
|
+
o.separator ""
|
45
|
+
o.separator "Directory analysis and verification:"
|
46
|
+
|
47
|
+
o.on("--analyze [path]", String, "Generage a fingerprint of the given path and save it for later verification.") do |path|
|
48
|
+
OPTIONS[:mode] = :analyze
|
49
|
+
OPTIONS[:root] = path
|
50
|
+
end
|
51
|
+
|
52
|
+
o.on("--verify [path]", String, "Verify a given path based on a previously saved fingerprint.") do |path|
|
53
|
+
OPTIONS[:mode] = :verify
|
54
|
+
OPTIONS[:root] = path
|
55
|
+
end
|
56
|
+
|
57
|
+
o.on("-n name", String, "Specify the name of the fingerprint file (default #{OPTIONS[:name]}).") do |name|
|
58
|
+
OPTIONS[:name] = name
|
59
|
+
end
|
60
|
+
|
61
|
+
o.on("-f", "Force any operation to complete despite warnings.") do
|
62
|
+
OPTIONS[:force] = true
|
63
|
+
end
|
64
|
+
|
65
|
+
o.separator ""
|
66
|
+
o.separator "Low level operations:"
|
67
|
+
|
39
68
|
o.on("-c", "Compare the given fingerprints. Check that the second fingerprint is a superset of the first.") do
|
40
69
|
OPTIONS[:mode] = :check
|
41
70
|
end
|
@@ -49,19 +78,59 @@ ARGV.options do |o|
|
|
49
78
|
end
|
50
79
|
|
51
80
|
o.separator ""
|
52
|
-
o.separator "Help and Copyright information"
|
81
|
+
o.separator "Help and Copyright information:"
|
53
82
|
|
54
83
|
o.on_tail("--copy", "Display copyright information") {
|
55
|
-
puts "#{script_name} v#{Fingerprint::VERSION::STRING}. Copyright (c)
|
56
|
-
puts "See http://www.oriontransfer.co.nz/ for more information."
|
84
|
+
$stderr.puts "#{script_name} v#{Fingerprint::VERSION::STRING}. Copyright (c) 2011 Samuel Williams. Released under the MIT license."
|
85
|
+
$stderr.puts "See http://www.oriontransfer.co.nz/ for more information."
|
57
86
|
|
58
87
|
exit
|
59
88
|
}
|
60
89
|
|
61
|
-
o.on_tail("-h", "--help", "Show this help message.") { puts o; exit }
|
90
|
+
o.on_tail("-h", "--help", "Show this help message.") { $stderr.puts o; exit }
|
62
91
|
end.parse!
|
63
92
|
|
93
|
+
unless File.directory? OPTIONS[:root]
|
94
|
+
$stderr.puts "Path #{OPTIONS[:root]} doesn't exist!"
|
95
|
+
exit(255)
|
96
|
+
end
|
97
|
+
|
64
98
|
case (OPTIONS[:mode])
|
99
|
+
when :analyze
|
100
|
+
output_file = Pathname.new(OPTIONS[:root]) + OPTIONS[:name]
|
101
|
+
|
102
|
+
if output_file.exist? && !OPTIONS[:force]
|
103
|
+
$stderr.puts "Output file #{output_file} already exists. Aborting."
|
104
|
+
exit(2)
|
105
|
+
end
|
106
|
+
|
107
|
+
options = {}
|
108
|
+
options[:verbose] = true if OPTIONS[:verbose]
|
109
|
+
|
110
|
+
File.open(output_file, "w") do |io|
|
111
|
+
options[:output] = io
|
112
|
+
|
113
|
+
Fingerprint::Scanner.scan_paths([OPTIONS[:root]], options)
|
114
|
+
end
|
115
|
+
when :verify
|
116
|
+
error_count = 0
|
117
|
+
|
118
|
+
input_file = Pathname.new(OPTIONS[:root]) + OPTIONS[:name]
|
119
|
+
|
120
|
+
scanner = Fingerprint::Scanner.scan_paths([OPTIONS[:root]])
|
121
|
+
scanner.output.seek(0)
|
122
|
+
|
123
|
+
File.open(input_file, "r") do |io|
|
124
|
+
error_count += Fingerprint::Checker.check_files(io, scanner.output)
|
125
|
+
end
|
126
|
+
|
127
|
+
if error_count == 0
|
128
|
+
$stderr.puts "Data verified, 0 errors found."
|
129
|
+
exit(0)
|
130
|
+
else
|
131
|
+
$stderr.puts "Data inconsistent, #{error_count} errors found!"
|
132
|
+
exit(1)
|
133
|
+
end
|
65
134
|
when :scan
|
66
135
|
roots = ARGV
|
67
136
|
roots << Dir.pwd if roots.size == 0
|
data/lib/fingerprint/checker.rb
CHANGED
@@ -92,17 +92,21 @@ module Fingerprint
|
|
92
92
|
# Helper function to check two fingerprint files.
|
93
93
|
def self.check_files(master, copy, &block)
|
94
94
|
error_count = 0
|
95
|
-
|
95
|
+
|
96
|
+
master = File.open(master) unless master.respond_to? :read
|
97
|
+
copy = File.open(copy) unless copy.respond_to? :read
|
98
|
+
|
99
|
+
checker = Checker.new(master, copy)
|
96
100
|
|
97
101
|
checker.check do |hash, path|
|
98
102
|
error_count += 1
|
99
103
|
|
100
104
|
if !checker.file_paths[path]
|
101
|
-
$stderr.puts "
|
105
|
+
$stderr.puts "File #{path.dump} is missing!"
|
102
106
|
elsif checker.file_paths[path] != hash
|
103
|
-
$stderr.puts "
|
107
|
+
$stderr.puts "File #{path.dump} is different!"
|
104
108
|
else
|
105
|
-
$stderr.puts "Unknown error for path
|
109
|
+
$stderr.puts "Unknown error for path #{path.dump}"
|
106
110
|
end
|
107
111
|
end
|
108
112
|
|
data/lib/fingerprint/version.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 1.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Samuel Williams
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-07-
|
17
|
+
date: 2011-07-20 00:00:00 +12:00
|
18
18
|
default_executable: fingerprint
|
19
19
|
dependencies: []
|
20
20
|
|