jammit-s3 0.6.0.1 → 0.6.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jammit-s3'
3
- s.version = '0.6.0.1'
3
+ s.version = '0.6.0.2'
4
4
 
5
5
  s.homepage = "http://documentcloud.github.com/jammit/"
6
6
  s.summary = "Asset Packaging for Rails with Deployment to S3/Cloudfront"
@@ -1,4 +1,5 @@
1
1
  require 'mimemagic'
2
+ require 'digest/md5'
2
3
 
3
4
  module Jammit
4
5
  class S3Uploader
@@ -56,17 +57,30 @@ module Jammit
56
57
  use_gzip = true
57
58
  remote_path = remote_path.gsub(/\.gz$/, "")
58
59
  end
60
+
61
+ # check if the file already exists on s3
62
+ begin
63
+ obj = @bucket.objects.find_first(remote_path)
64
+ rescue
65
+ obj = nil
66
+ end
59
67
 
60
- log "pushing file to s3: #{remote_path}"
61
-
62
- # save to s3
63
- new_object = @bucket.objects.build(remote_path)
64
- new_object.cache_control = @cache_control if @cache_control
65
- new_object.content_type = MimeMagic.by_path(remote_path)
66
- new_object.content = open(local_path)
67
- new_object.content_encoding = "gzip" if use_gzip
68
- new_object.acl = @acl if @acl
69
- new_object.save
68
+ # if the object does not exist, or if the MD5 Hash / etag of the
69
+ # file has changed, upload it
70
+ if !obj || (obj.etag != Digest::MD5.hexdigest(File.read(local_path)))
71
+ log "pushing file to s3: #{remote_path}"
72
+
73
+ # save to s3
74
+ new_object = @bucket.objects.build(remote_path)
75
+ new_object.cache_control = @cache_control if @cache_control
76
+ new_object.content_type = MimeMagic.by_path(remote_path)
77
+ new_object.content = open(local_path)
78
+ new_object.content_encoding = "gzip" if use_gzip
79
+ new_object.acl = @acl if @acl
80
+ new_object.save
81
+ else
82
+ log "file has not changed: #{remote_path}"
83
+ end
70
84
  end
71
85
  end
72
86
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jammit-s3
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.0.1
5
+ version: 0.6.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jacques Crocker
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-12 00:00:00 -08:00
13
+ date: 2011-03-18 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -75,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- hash: 2557465707510469440
78
+ hash: 1181583477013586615
79
79
  segments:
80
80
  - 0
81
81
  version: "0"
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - ">="
86
86
  - !ruby/object:Gem::Version
87
- hash: 2557465707510469440
87
+ hash: 1181583477013586615
88
88
  segments:
89
89
  - 0
90
90
  version: "0"