s3sync 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8737f906e6e83042d2edb667c33705fe96f24bbd
4
- data.tar.gz: c0d333e0b488014eb6e2273933019ba0ec58c9fb
3
+ metadata.gz: 8672f843e8dfe49d8332c6ed8212679926efdca1
4
+ data.tar.gz: 3142cb4b5b510800de393dd1a42033805f251eca
5
5
  SHA512:
6
- metadata.gz: d94b3ec845ed9e48966045120a8c2292e5df64852c71d50eb3f0dec8d32e46d31082d8fd2380c7225aa856b98673cd20a02e119f2396aeaed5e6b5eb35490196
7
- data.tar.gz: 3d22969a836de20ad4326ad5a134b3a221fa26a573ea4e0424186f6effb69ad63c7800f40fb49fecfc6ab616d306de489d54fd9c88b0edaf0c91042e6c413f12
6
+ metadata.gz: a937fce93d46e724f586fce116a922bf0c6e993a893054b596963f68ac4c8480ecab166097862232c6df771aece1760c9e03dd462fac43bb34d52d953d1b1933
7
+ data.tar.gz: a17295b31fbc18d2d5e9a5476d0ba1bf3c54509bfd1c4425aea8d910bca15b4c84e2b1fe657d4ee447310750166d6d33d2871d7a24cdd88db1cf157b8271f105
@@ -74,7 +74,7 @@ module S3Sync
74
74
 
75
75
  def read_from_env
76
76
  REQUIRED_VARS.each do |v|
77
- self[v] = ENV[v.to_s] unless ENV[v.to_s].nil?
77
+ self[v.to_s] = ENV[v.to_s] unless ENV[v.to_s].nil?
78
78
  end
79
79
  end
80
80
 
@@ -71,14 +71,18 @@ module S3Sync
71
71
  class Node
72
72
  include Comparable
73
73
 
74
+ SMALL_FILE = 50 * 1024 # 50.kilobytes
75
+
74
76
  attr_accessor :base
75
77
  attr_accessor :path
76
78
  attr_accessor :size
79
+ attr_accessor :small_comparator
77
80
 
78
- def initialize base, path, size
81
+ def initialize base, path, size, small_comparator = nil
79
82
  @base = base
80
83
  @path = path
81
84
  @size = size
85
+ @small_comparator = small_comparator
82
86
  end
83
87
 
84
88
  def full
@@ -86,20 +90,21 @@ module S3Sync
86
90
  end
87
91
 
88
92
  def == other
89
- full == other.full and @size == other.size
90
- end
91
-
92
- def <=> other
93
- if self.size < other.size
94
- -1
95
- elsif self.size > other.size
96
- 1
97
- else
98
- 0
99
- end
93
+ @size == other.size && compare_small_comparators(other)
100
94
  end
101
95
 
102
96
  alias eql? ==
97
+
98
+ private
99
+
100
+ # If files are small and both nodes have a comparator, we can call an extra
101
+ # provided block to verify equality. This allows
102
+ def compare_small_comparators(other)
103
+ return true if @size > SMALL_FILE || other.size > SMALL_FILE
104
+ return true if small_comparator.nil? || other.small_comparator.nil?
105
+
106
+ small_comparator.call == other.small_comparator.call
107
+ end
103
108
  end
104
109
 
105
110
  class LocalDirectory
@@ -136,7 +141,8 @@ module S3Sync
136
141
 
137
142
  # We only need the relative path here
138
143
  file_name = file.gsub(/^#{@source}\/?/, '').squeeze('/')
139
- node = Node.new(@source.squeeze('/'), file_name, st.size)
144
+ small_comparator = lambda { Digest::MD5.hexdigest File.read(file) }
145
+ node = Node.new(@source.squeeze('/'), file_name, st.size, small_comparator)
140
146
  nodes[node.path] = node
141
147
  end
142
148
 
@@ -153,7 +159,7 @@ module S3Sync
153
159
  value2 = hash2.delete key
154
160
  if value2.nil?
155
161
  to_add_to_2 << value
156
- elsif value2.size == value.size
162
+ elsif value2 == value
157
163
  same << value
158
164
  else
159
165
  to_add_to_2 << value
@@ -297,7 +303,9 @@ module S3Sync
297
303
 
298
304
  nodes = {}
299
305
  @args.s3.buckets[location.bucket].objects.with_prefix(dir || "").to_a.collect do |obj|
300
- node = Node.new(location.path, obj.key, obj.content_length)
306
+ # etag comes back with quotes (obj.etag.inspcet # => "\"abc...def\""
307
+ small_comparator = lambda { obj.etag[/[a-z0-9]+/] }
308
+ node = Node.new(location.path, obj.key, obj.content_length, small_comparator)
301
309
  nodes[node.path] = node
302
310
  end
303
311
  return nodes
@@ -23,5 +23,5 @@
23
23
  # THE SOFTWARE.
24
24
 
25
25
  module S3Sync
26
- VERSION = "2.0.1"
26
+ VERSION = "2.0.2"
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lincoln de Sousa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-22 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk