Narnach-md5_wrapper 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -0
- data/lib/md5_wrapper.rb +5 -5
- data/md5_wrapper.gemspec +1 -1
- data/test/md5_wrapper_test.rb +23 -2
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -28,4 +28,18 @@ Check the correct md5 hexdigest against a file.
|
|
28
28
|
Check an incorrect md5 hexdigest against a file.
|
29
29
|
Md5Wrapper.check_md5sum('foo.txt', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') #=> false
|
30
30
|
|
31
|
+
== Changelog
|
32
|
+
|
33
|
+
== Version 0.3.1
|
34
|
+
* Made Md5Wrapper work with filenames with spaces.
|
35
|
+
|
36
|
+
== Version 0.3.0
|
37
|
+
* Md5Wrapper is now available as RubyGem as well as Rails plugin
|
38
|
+
* Added a simple test for each method on Md5Wrapper.
|
39
|
+
* Renamed generated code to use Md5Wrapper instead of Md5sumWrapper.
|
40
|
+
* Added plugin.
|
41
|
+
|
42
|
+
== Contributors
|
43
|
+
* Filip 'FiXato' Slagter
|
44
|
+
|
31
45
|
Copyright (c) 2008 Wes Oldenbeuving, released under the MIT license
|
data/lib/md5_wrapper.rb
CHANGED
@@ -5,23 +5,23 @@ class Md5Wrapper
|
|
5
5
|
def check_md5sum(filename, md5sum)
|
6
6
|
raise ArgumentError, "Invalid md5sum" unless md5sum.size == 32
|
7
7
|
raise ArgumentError, "Invalid file" unless File.exist? filename and File.file? filename and File.readable? filename
|
8
|
-
|
8
|
+
|
9
9
|
if RUBY_PLATFORM =~ /darwin/
|
10
|
-
md5 = `md5 #{filename} 2>&1`.strip[-32,32]
|
10
|
+
md5 = `md5 "#{filename}" 2>&1`.strip[-32,32]
|
11
11
|
return md5 == md5sum
|
12
12
|
else # linux
|
13
13
|
cmd = "echo \"#{md5sum} *#{filename}\" | md5sum -c --status 2>&1"
|
14
14
|
return system(cmd)
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Extract the md5 hexdigest from a file.
|
19
19
|
def get_md5sum(filename)
|
20
20
|
raise ArgumentError, "Invalid file" unless File.exist? filename and File.file? filename and File.readable? filename
|
21
21
|
if RUBY_PLATFORM =~ /darwin/
|
22
|
-
return `md5 #{filename} 2>&1`.strip[-32,32]
|
22
|
+
return `md5 "#{filename}" 2>&1`.strip[-32,32]
|
23
23
|
else # linux
|
24
|
-
return `md5sum -b #{filename} 2>&1`[0,32]
|
24
|
+
return `md5sum -b "#{filename}" 2>&1`[0,32]
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/md5_wrapper.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.name = 'md5_wrapper'
|
4
4
|
s.summary = "Md5Wrapper wraps the command line utilities md5sum (Linux) and md5 (Mac)."
|
5
5
|
s.description = "It allows obtaining the md5 hexdigest of a file and checking that a file has a specific md5 hexdigest."
|
6
|
-
s.version = '0.3.
|
6
|
+
s.version = '0.3.1'
|
7
7
|
s.date = '2008-08-05'
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Wes Oldenbeuving"]
|
data/test/md5_wrapper_test.rb
CHANGED
@@ -1,17 +1,38 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
|
1
3
|
require 'test/unit'
|
2
4
|
require 'md5_wrapper'
|
5
|
+
require 'tempfile'
|
3
6
|
|
4
7
|
class Md5WrapperTest < Test::Unit::TestCase
|
5
8
|
def setup
|
6
9
|
@fixture = File.expand_path(File.join(File.dirname(__FILE__),'fixtures','test.txt'))
|
7
10
|
@md5sum = 'd8e8fca2dc0f896fd7cb4cb0031ba249'
|
8
11
|
end
|
9
|
-
|
12
|
+
|
10
13
|
def test_get_md5sum
|
11
14
|
assert_equal @md5sum, Md5Wrapper.get_md5sum(@fixture)
|
12
15
|
end
|
13
|
-
|
16
|
+
|
14
17
|
def test_check_md5sum
|
15
18
|
assert Md5Wrapper.check_md5sum(@fixture, @md5sum)
|
16
19
|
end
|
20
|
+
|
21
|
+
def test_get_md5sum_for_filenames_with_spaces
|
22
|
+
Tempfile.open('text file with spaces.txt') do |f|
|
23
|
+
File.open(f.path,'w') do |fp|
|
24
|
+
fp.puts 'test'
|
25
|
+
end
|
26
|
+
assert_equal @md5sum, Md5Wrapper.get_md5sum(f.path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_check_md5sum_for_filenames_with_spaces
|
31
|
+
Tempfile.open('text file with spaces.txt') do |f|
|
32
|
+
File.open(f.path,'w') do |fp|
|
33
|
+
fp.puts 'test'
|
34
|
+
end
|
35
|
+
assert Md5Wrapper.check_md5sum(f.path,@md5sum)
|
36
|
+
end
|
37
|
+
end
|
17
38
|
end
|