rhcf-utils 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/rhcf/utils/download_cache.rb +14 -4
- data/lib/rhcf/utils/version.rb +1 -1
- data/spec/lib/rhcf/utils/download_cache_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bbb18233c4eb4dee23a92dc24406682cd1e17b6
|
4
|
+
data.tar.gz: 90ddbf00c82e1965d2894816b01b75bfe10950b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5951a56a503f1e80dac9d927acc992b3d460683761700c99146a3324c6df788bf2e9bd00bf8fa38408166eccab635db01daa2cd927738b2ee28fbd4a9054d05
|
7
|
+
data.tar.gz: dc5a16c1d983e8d97e94196b78ca0664abdbc13f45229144d40c5a9b207e22678d16f130f515b1bf0c2f3970aae01e82c2e2c48d6a58c828152bf091d077f835
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'uri'
|
2
|
-
require '
|
2
|
+
require 'net/http'
|
3
3
|
require 'fileutils'
|
4
4
|
require 'digest/md5'
|
5
5
|
|
@@ -22,12 +22,22 @@ module Rhcf
|
|
22
22
|
|
23
23
|
|
24
24
|
def download!(url, outfile)
|
25
|
-
|
25
|
+
uri = URI(url)
|
26
|
+
expected_file_size = nil
|
27
|
+
Net::HTTP.start(uri.host) do |http|
|
28
|
+
resp = http.get(uri.path)
|
29
|
+
|
30
|
+
expected_file_size = resp.body.size
|
26
31
|
mkdir_p(File.dirname(outfile))
|
27
32
|
File.open(outfile, 'wb') do |fd|
|
28
|
-
fd.write(
|
33
|
+
fd.write(resp.body)
|
29
34
|
end
|
30
35
|
end
|
36
|
+
|
37
|
+
if expected_file_size != File.size(outfile)
|
38
|
+
raise "Different file size expected: '%d' bytes got: '%d' bytes " % [expected_file_size, File.size(outfile)]
|
39
|
+
end
|
40
|
+
raise "Empty file" if File.zero?(outfile)
|
31
41
|
outfile
|
32
42
|
end
|
33
43
|
|
@@ -38,7 +48,7 @@ module Rhcf
|
|
38
48
|
|
39
49
|
def self.hit_fname?(fname, ttl)
|
40
50
|
|
41
|
-
if File.exist?(fname)
|
51
|
+
if File.exist?(fname) and !File.zero?(fname)
|
42
52
|
if ttl
|
43
53
|
File::Stat.new(fname).ctime > Time.now - ttl
|
44
54
|
else
|
data/lib/rhcf/utils/version.rb
CHANGED
@@ -32,7 +32,7 @@ describe Rhcf::Utils::DownloadCache do
|
|
32
32
|
before(:each) do
|
33
33
|
FileUtils.rm_rf "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/a/e/a/aea455b4b37a2d4240a6b054ca0b0d5f8"
|
34
34
|
FileUtils.mkdir_p "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/e/7/f/e7fb5389b6646ebb89aaa5502b75a440"
|
35
|
-
|
35
|
+
IO.write("/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/e/7/f/e7fb5389b6646ebb89aaa5502b75a440/imagens-do-dia-20131023-04-original.jpg", 'noempty')
|
36
36
|
end
|
37
37
|
it "should return true if file downloaded and ttl is null" do
|
38
38
|
cache_of_30s.filename_for(img_url).should == '/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/e/7/f/e7fb5389b6646ebb89aaa5502b75a440/imagens-do-dia-20131023-04-original.jpg'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhcf-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Romeu Fonseca
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|