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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9909d07e5aa545cbf9b72db81d6149001d00e90a
4
- data.tar.gz: eae25b18c3232384492b5cae2e580680e360f99e
3
+ metadata.gz: 9bbb18233c4eb4dee23a92dc24406682cd1e17b6
4
+ data.tar.gz: 90ddbf00c82e1965d2894816b01b75bfe10950b2
5
5
  SHA512:
6
- metadata.gz: 811297382e1341960a989f99da58968501a9c3efca6966fb0abb34d07f309f483d759af9ce2acbac0a5866ee9a14767cba60ebc61a2f87b1eca70c3e06e9a812
7
- data.tar.gz: 9f1e833fd8bd6acf277febc0cde75fe934ba2918f79e533dbe0e6936a1677585eaffa7f928c83e73201609a8816eda14e4eabfeeca5e807db725c0b9fa40f517
6
+ metadata.gz: a5951a56a503f1e80dac9d927acc992b3d460683761700c99146a3324c6df788bf2e9bd00bf8fa38408166eccab635db01daa2cd927738b2ee28fbd4a9054d05
7
+ data.tar.gz: dc5a16c1d983e8d97e94196b78ca0664abdbc13f45229144d40c5a9b207e22678d16f130f515b1bf0c2f3970aae01e82c2e2c48d6a58c828152bf091d077f835
@@ -1,5 +1,5 @@
1
1
  require 'uri'
2
- require 'open-uri'
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
- open(url, "rb") do |down|
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(down.read)
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
@@ -1,5 +1,5 @@
1
1
  module Rhcf
2
2
  module Utils
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -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
- FileUtils.touch "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/e/7/f/e7fb5389b6646ebb89aaa5502b75a440/imagens-do-dia-20131023-04-original.jpg"
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.3
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-10 00:00:00.000000000 Z
11
+ date: 2014-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler