checksummer 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/checksummer.gemspec +2 -2
- data/features/checksum.feature +15 -0
- data/lib/checksummer.rb +16 -8
- data/lib/checksummer_file.rb +1 -0
- data/spec/checksummer_file_spec.rb +10 -0
- data/spec/checksummer_spec.rb +35 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/checksummer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{checksummer}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tobias Schwab"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-04-04}
|
13
13
|
s.default_executable = %q{checksummer}
|
14
14
|
s.description = %q{Replace files with links to md5 files}
|
15
15
|
s.email = %q{tobias.schwab@dynport.de}
|
data/features/checksum.feature
CHANGED
@@ -78,3 +78,18 @@ Feature: Checksum
|
|
78
78
|
| symlink | path | content |
|
79
79
|
| src/file10.txt | dst/a/9/e/3/a9e3737bb4cf960ff521c4ad4c8275e7 | file 10 |
|
80
80
|
| src/file20.txt | dst/0/6/7/f/067f81212cf0fb2e982bd628a8606f97 | file 20 |
|
81
|
+
|
82
|
+
Scenario: Checksum single files
|
83
|
+
Given I clear tmp
|
84
|
+
And the following files exists:
|
85
|
+
| path | content |
|
86
|
+
| src/file10.txt | file 10 |
|
87
|
+
| src/file11.txt | file 11 |
|
88
|
+
| src/file20.txt | file 20 |
|
89
|
+
| src/file21.txt | file 21 |
|
90
|
+
And the directory "dst" exists
|
91
|
+
When I call "checksummer tmp/src/file11.txt tmp/dst"
|
92
|
+
Then I should see 1 files in "tmp/dst"
|
93
|
+
Then I should see the following files
|
94
|
+
| symlink | path | content |
|
95
|
+
| src/file11.txt | dst/7/1/5/0/715081268e5e053a7e89daf6c155244a | file 11 |
|
data/lib/checksummer.rb
CHANGED
@@ -8,6 +8,10 @@ class Checksummer
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.run_for_args(args)
|
11
|
+
if args.include?("--version")
|
12
|
+
puts File.read(File.expand_path("../VERSION", File.dirname(__FILE__)))
|
13
|
+
return
|
14
|
+
end
|
11
15
|
directory, checksum_to = args[0,2]
|
12
16
|
sleep = 0.1
|
13
17
|
if idx = args.index("--sleep")
|
@@ -15,14 +19,18 @@ class Checksummer
|
|
15
19
|
sleep = args.delete_at(idx).to_i / 1000.0
|
16
20
|
end
|
17
21
|
if directory && checksum_to && File.directory?(checksum_to)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
if File.file?(directory)
|
23
|
+
puts ChecksummerFile.from_line(directory).checksum_to!(checksum_to).to_json
|
24
|
+
else
|
25
|
+
started_at = Time.now
|
26
|
+
lines = directory == "--stdin" ? $stdin.readlines : find(directory, args[2..-1].join(" "))
|
27
|
+
total = lines.count
|
28
|
+
lines.each_with_index do |line, index|
|
29
|
+
extra = { :index => index + 1, :total => lines.count, :started_at => started_at.iso8601 }
|
30
|
+
puts ChecksummerFile.from_line(line).checksum_to!(checksum_to).merge(extra).to_json
|
31
|
+
$stdout.flush
|
32
|
+
sleep sleep if !Range.new(0,7).include?(Time.now.hour)
|
33
|
+
end
|
26
34
|
end
|
27
35
|
return true
|
28
36
|
end
|
data/lib/checksummer_file.rb
CHANGED
@@ -164,6 +164,7 @@ describe ChecksummerFile do
|
|
164
164
|
describe "with the file being a symlink" do
|
165
165
|
before(:each) do
|
166
166
|
File.stub(:symlink?).with("/some/text.csv").and_return true
|
167
|
+
File.stub!(:realpath).and_return "/some/real/path"
|
167
168
|
end
|
168
169
|
|
169
170
|
it "does not copy the file when already exists" do
|
@@ -181,6 +182,15 @@ describe ChecksummerFile do
|
|
181
182
|
file.checksum_to!("/tmp/data")
|
182
183
|
end
|
183
184
|
|
185
|
+
it "calls File.realpath with path" do
|
186
|
+
File.should_receive(:realpath).with("/some/text.csv").and_return "/real_path"
|
187
|
+
file.checksum_to!("/tmp/data")
|
188
|
+
end
|
189
|
+
|
190
|
+
it "sets the realpath" do
|
191
|
+
file.checksum_to!("/tmp/data")[:realpath].should == "/some/real/path"
|
192
|
+
end
|
193
|
+
|
184
194
|
it "returns :exists" do
|
185
195
|
file.checksum_to!("/tmp/data")[:status].should == :was_symlink
|
186
196
|
end
|
data/spec/checksummer_spec.rb
CHANGED
@@ -47,6 +47,11 @@ describe "Checksummer" do
|
|
47
47
|
Checksummer.stub!(:puts)
|
48
48
|
end
|
49
49
|
|
50
|
+
it "prints the version when --version given" do
|
51
|
+
Checksummer.should_receive(:puts).with(/\d+\.\d+.\d+/)
|
52
|
+
Checksummer.run_for_args("--version")
|
53
|
+
end
|
54
|
+
|
50
55
|
it "prints usage when no checksum_to found" do
|
51
56
|
Checksummer.should_receive(:puts).with Checksummer.usage
|
52
57
|
Checksummer.run_for_args([])
|
@@ -133,6 +138,36 @@ describe "Checksummer" do
|
|
133
138
|
Checksummer.run_for_args(["/tmp", "/tmp"])
|
134
139
|
end
|
135
140
|
end
|
141
|
+
|
142
|
+
describe "with a direct file given" do
|
143
|
+
let(:checksum_file) { double("checksummer_file", :checksum_to! => true)}
|
144
|
+
|
145
|
+
before(:each) do
|
146
|
+
File.stub!(:file?).and_return true
|
147
|
+
ChecksummerFile.stub!(:from_line).and_return(checksum_file)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "calls File.file? on src" do
|
151
|
+
File.should_receive(:file?).with("/some/path").and_return true
|
152
|
+
Checksummer.run_for_args(["/some/path", "/tmp"])
|
153
|
+
end
|
154
|
+
|
155
|
+
it "calls ChecksummerFile.from_line with file" do
|
156
|
+
ChecksummerFile.should_receive(:from_line).with("/some/path").and_return(checksum_file)
|
157
|
+
Checksummer.run_for_args(["/some/path", "/tmp"])
|
158
|
+
end
|
159
|
+
|
160
|
+
it "calls checksum_to! with dst" do
|
161
|
+
checksum_file.should_receive(:checksum_to!).with("/tmp")
|
162
|
+
Checksummer.run_for_args(["/some/path", "/tmp"])
|
163
|
+
end
|
164
|
+
|
165
|
+
it "puts result of checksum_to!" do
|
166
|
+
checksum_file.stub!(:checksum_to!).and_return(:some => "result")
|
167
|
+
Checksummer.should_receive(:puts).with("{\"some\":\"result\"}")
|
168
|
+
Checksummer.run_for_args(["/some/path", "/tmp"])
|
169
|
+
end
|
170
|
+
end
|
136
171
|
end
|
137
172
|
|
138
173
|
describe "#integration" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tobias Schwab
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-04-04 00:00:00 +02:00
|
18
18
|
default_executable: checksummer
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -184,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
184
184
|
requirements:
|
185
185
|
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
hash:
|
187
|
+
hash: 1489982257138281223
|
188
188
|
segments:
|
189
189
|
- 0
|
190
190
|
version: "0"
|