filbunke 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/filbunke.gemspec +2 -2
  3. data/lib/filbunke/client.rb +47 -33
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.4
1
+ 1.1.5
data/filbunke.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{filbunke}
8
- s.version = "1.1.4"
8
+ s.version = "1.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wouter de Bie"]
12
- s.date = %q{2010-11-10}
12
+ s.date = %q{2010-11-15}
13
13
  s.default_executable = %q{filbunked}
14
14
  s.description = %q{Filbunke client and library}
15
15
  s.email = %q{wouter@deltaprojects.se}
@@ -1,6 +1,7 @@
1
1
  require 'json'
2
2
  require 'net/http'
3
3
  require 'fileutils'
4
+ require 'digest/md5'
4
5
 
5
6
  module Filbunke
6
7
  class Client
@@ -25,19 +26,22 @@ module Filbunke
25
26
  failure = false
26
27
  updated_files.each do |raw_file|
27
28
  file = File.new(raw_file)
28
- if file.url =~ /^http:\/\//
29
- local_file_path = ::File.join(repository.local_path, file.path)
30
- if update_http_file!(file, local_file_path) then
31
- @callbacks.each do |callback|
32
- callback.on_update(file)
29
+
30
+ local_file_path = ::File.join(repository.local_path, file.path)
31
+ if file_needs_update?(file, local_file_path)
32
+ if file.url =~ /^http:\/\//
33
+ if update_http_file!(file, local_file_path) then
34
+ @callbacks.each do |callback|
35
+ callback.on_update(file)
36
+ end
37
+ yield file
38
+ else
39
+ @logger.log "Unable to get file #{file.url}/#{file.path}!"
40
+ failure = true
33
41
  end
34
- yield file
35
42
  else
36
- @logger.log "Unable to get file #{file.url}/#{file.path}!"
37
- failure = true
43
+ raise "Unsupported protocol for file: #{file.inspect}"
38
44
  end
39
- else
40
- raise "Unsupported protocol for file: #{file.inspect}"
41
45
  end
42
46
  end
43
47
  failure ? last_checkpoint : (updates["checkpoint"] || last_checkpoint)
@@ -74,19 +78,30 @@ module Filbunke
74
78
 
75
79
  private
76
80
 
81
+ def file_needs_update?(file, local_file_path)
82
+ return true if file.hash.nil || file.hash == ""
83
+
84
+ return true unless File.exists?(local_file_path)
85
+
86
+ local_hash = Digest::MD5.hexdigest(File.read(local_file_path))
87
+ local_hash != file.hash
88
+ end
89
+
77
90
  def get_updated_file_list(last_checkpoint)
91
+
78
92
  begin
79
93
  updates_http = Net::HTTP.new(@repository.host, @repository.port)
80
94
  updates_http.start do |http|
81
95
  begin
82
- updates_path = "/#{UPDATES_ACTION}/#{@repository.name}?#{FROM_CHECKPOINT_KEY}=#{last_checkpoint}"
83
- request = Net::HTTP::Get.new(updates_path)
84
- response = http.request(request)
85
- if response.code.to_i == 200
86
- JSON.parse(response.body)
87
- else
88
- @logger.log "Failed to download updates for #{@repository.name}, error code = #{response.code}"
89
- end
96
+ updates_path = "/#{UPDATES_ACTION}/#{@repository.name}?#{FROM_CHECKPOINT_KEY}=#{last_checkpoint}"
97
+ request = Net::HTTP::Get.new(updates_path)
98
+ response = http.request(request)
99
+ if response.code.to_i == 200
100
+ JSON.parse(response.body)
101
+ else
102
+ @logger.log "Failed to download updates for #{@repository.name}, error code = #{response.code}"
103
+ {}
104
+ end
90
105
  rescue StandardError => e
91
106
  @logger.log "Error getting file list: #{e.message}! Retrying later.."
92
107
  {}
@@ -100,25 +115,24 @@ module Filbunke
100
115
 
101
116
  def update_http_file!(file, local_file_path)
102
117
  begin
103
- uri = URI.parse(file.url)
104
- file_http=Net::HTTP.new(uri.host, uri.port)
105
- file_http.start do |http|
106
- request = Net::HTTP::Get.new(uri.path)
107
- request.basic_auth @repository.user, @repository.pass if @repository.user
108
- response = http.request(request)
109
- if response.code.to_i == 200
110
- write_file!(local_file_path, response.body)
111
- elsif response.code.to_i == 404
112
- delete_file!(local_file_path)
113
- else
114
- @logger.log "Failed to update file #{uri}, error code = #{response.code}"
118
+ uri = URI.parse(file.url)
119
+ file_http=Net::HTTP.new(uri.host, uri.port)
120
+ file_http.start do |http|
121
+ request = Net::HTTP::Get.new(uri.path)
122
+ request.basic_auth @repository.user, @repository.pass if @repository.user
123
+ response = http.request(request)
124
+ if response.code.to_i == 200
125
+ write_file!(local_file_path, response.body)
126
+ elsif response.code.to_i == 404
127
+ delete_file!(local_file_path)
128
+ else
129
+ @logger.log "Failed to update file #{uri}, error code = #{response.code}"
130
+ end
131
+ return true
115
132
  end
116
- return true
117
- end
118
133
  rescue StandardError => e
119
134
  return false
120
135
  end
121
-
122
136
  end
123
137
 
124
138
  def write_file!(file_path, contents)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 4
9
- version: 1.1.4
8
+ - 5
9
+ version: 1.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Wouter de Bie
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-10 00:00:00 +01:00
17
+ date: 2010-11-15 00:00:00 +01:00
18
18
  default_executable: filbunked
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency