lib/datapimp/sync/s3_bucket.rb in datapimp-1.2.7 vs lib/datapimp/sync/s3_bucket.rb in datapimp-1.2.8

- old
+ new

@@ -119,10 +119,15 @@ log "Saving deploy manifest. #{ deploy_manifest.keys.length } entries" deploy_manifest_path.open("w+") {|fh| fh.write(deploy_manifest.to_json) } end + def run_reset_action(options={}) + bucket = directories.get(remote) + bucket.files.each {|f| key = f.key; f.delete rescue nil; f.destroy rescue nil; log "Deleting #{ key }"} + end + def run_pull_action(options={}) directories = Datapimp::Sync.amazon.storage.directories bucket = directories.get(remote) options = options.to_mash @@ -131,25 +136,31 @@ FileUtils.mkdir_p(local_path) end bucket.files.each do |file| local_file = local_path.join(file.key) - next if local_file.exist? && file.etag == Digest::MD5.hexdigest(local_file.read) + if local_file.exist? && file.etag == Digest::MD5.hexdigest(local_file.read) + log "Skipping #{ file.key }" + next + end + FileUtils.mkdir_p(local_file.dirname) - local_file.open("w+") {|fh| log("Updated #{ file.key }"); fh.write(file.body) } + local_file.open("w+") {|fh| fh.write(file.body); log("Updated #{ file.key }"); } end end def run_create_action(options={}) directories = Datapimp::Sync.amazon.storage.directories + make_private = !!options[:make_private] + bucket = if existing = directories.get(remote) existing else - directories.create(key:remote, public: true) + directories.create(key:remote, public: !make_private) end storage.put_bucket_website(remote, :IndexDocument => 'index.html', :ErrorDocument => 'error.html') bucket @@ -164,9 +175,11 @@ run_create_action(options) elsif action == :update_acl run_update_acl_action(options) elsif action == :pull run_pull_action(options) + elsif action == :reset + run_reset_options(options) end end end end end