s3_meta_sync 0.2.3 → 0.3.0

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: 66fd72c5fa08fc841c1eabff28d2edcf17d1f9e7
4
- data.tar.gz: 84ebb0bcc5ea31e17f7963434d16901f96b92f81
3
+ metadata.gz: 5656a323ca7eaad2a794b645ff158819a2d1edd6
4
+ data.tar.gz: 47323041dbc94b89b34aa8dc821eb54dd9be3880
5
5
  SHA512:
6
- metadata.gz: 8ad3f56ec2eba6491ceb9c42d5aa60c563ce286d573799959861309e966af77fe7bcff0788ddf11a567fd9de66be101b1091d8eed70d00c90437f3e1f62fa3f4
7
- data.tar.gz: b69b8d36b3e2211ed6c8f9b11505fa5c5d00116096c5eaef5ef0bda4e9ed59ce51ed0c6d138fa30a2940d260cc647f15d6a51bd13868adbb95864ad39ba3d20c
6
+ metadata.gz: 3b8037f17c549849ab87b37c4587c68cdaaafe70d0532f556dbfd7e30a6f6d9a42ab1d28ffa6668d401e07ecfd2328282b94b366c54e94f3e0d740536e480ce5
7
+ data.tar.gz: 37130dbe101aa047ad4fdd30163a5cd20754985368eb2db6b4db98d84e72ae2a84e4fad4b99ea64d62d637d04cb89c0c20744ea6aec5c59eb4569079e2a16431
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,3 +1,3 @@
1
1
  module S3MetaSync
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/s3_meta_sync.rb CHANGED
@@ -4,6 +4,7 @@ require "yaml"
4
4
  require "digest/md5"
5
5
  require "optparse"
6
6
  require "fileutils"
7
+ require "tmpdir"
7
8
 
8
9
  require "aws/s3"
9
10
 
@@ -16,6 +17,7 @@ end
16
17
 
17
18
  module S3MetaSync
18
19
  RemoteWithoutMeta = Class.new(Exception)
20
+ RemoteCorrupt = Class.new(Exception)
19
21
  META_FILE = ".s3-meta-sync"
20
22
 
21
23
  class Syncer
@@ -64,10 +66,40 @@ module S3MetaSync
64
66
 
65
67
  log "Downloading: #{download.size} Deleting: #{delete.size}", true
66
68
 
67
- download_files(source, destination, download)
68
- delete_local_files(destination, delete)
69
- download_file(source, META_FILE, destination)
70
- delete_empty_folders(destination)
69
+ unless download.empty? && delete.empty?
70
+ Dir.mktmpdir do |dir|
71
+ copy_content(destination, dir)
72
+ download_files(source, dir, download)
73
+ delete_local_files(dir, delete)
74
+ download_file(source, META_FILE, dir)
75
+ verify_integrity!(dir)
76
+ delete_empty_folders(dir)
77
+ swap_in_directory(destination, dir)
78
+ end
79
+ end
80
+ end
81
+
82
+ def copy_content(destination, dir)
83
+ system "cp -R #{destination}/* #{dir} 2>/dev/null"
84
+ end
85
+
86
+ def swap_in_directory(destination, dir)
87
+ Dir.mktmpdir { |landfill| FileUtils.mv(destination, landfill) }
88
+ FileUtils.mv(dir, destination)
89
+ FileUtils.mkdir(dir) # make ensure in outside mktmpdir not blow up
90
+ end
91
+
92
+ def verify_integrity!(source)
93
+ file = "#{source}/#{META_FILE}"
94
+ old = File.read(file)
95
+ generate_meta(source)
96
+ new = File.read(file)
97
+ if new != old
98
+ log "old meta:\n#{old}\n\nnew meta:\n#{new}", true
99
+ raise RemoteCorrupt
100
+ end
101
+ ensure
102
+ File.write(file, old) if old
71
103
  end
72
104
 
73
105
  def upload_file(source, path, destination)
@@ -91,12 +123,17 @@ module S3MetaSync
91
123
  end
92
124
 
93
125
  def generate_meta(source)
94
- meta = Hash[Dir["#{source}/**/*"].select { |f| File.file?(f) }.map do |file|
95
- [file.sub("#{source}/", ""), Digest::MD5.file(file).to_s]
96
- end]
97
126
  file = "#{source}/#{META_FILE}"
98
127
  FileUtils.mkdir_p(File.dirname(file))
99
- File.write(file, meta.to_yaml)
128
+ File.write(file, meta_data(source).to_yaml)
129
+ end
130
+
131
+ def meta_data(source)
132
+ return {} unless File.directory?(source)
133
+ Dir.chdir(source) do
134
+ files = Dir["**/*"].select { |f| File.file?(f) }
135
+ Hash[files.map { |file| [file, Digest::MD5.file(file).to_s] }]
136
+ end
100
137
  end
101
138
 
102
139
  def read_meta(source)
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_meta_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -10,9 +10,9 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MRAwDgYDVQQDDAdtaWNo
13
+ MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MRAwDgYDVQQDDAdtaWNo
14
14
  YWVsMRcwFQYKCZImiZPyLGQBGRYHZ3Jvc3NlcjESMBAGCgmSJomT8ixkARkWAml0
15
- MB4XDTEzMDIwMzE4MTMxMVoXDTE0MDIwMzE4MTMxMVowPzEQMA4GA1UEAwwHbWlj
15
+ MB4XDTE0MDIwNDIwMjk0MVoXDTE1MDIwNDIwMjk0MVowPzEQMA4GA1UEAwwHbWlj
16
16
  aGFlbDEXMBUGCgmSJomT8ixkARkWB2dyb3NzZXIxEjAQBgoJkiaJk/IsZAEZFgJp
17
17
  dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMorXo/hgbUq97+kII9H
18
18
  MsQcLdC/7wQ1ZP2OshVHPkeP0qH8MBHGg6eYisOX2ubNagF9YTCZWnhrdKrwpLOO
@@ -20,16 +20,17 @@ cert_chain:
20
20
  6vHvcIHdzvc/OUkICttLbH+1qb6rsHUceqh+JrH4GrsJ5H4hAfIdyS2XMK7YRKbh
21
21
  h+IBu6dFWJJByzFsYmV1PDXln3UBmgAt65cmCu4qPfThioCGDzbSJrGDGLmw/pFX
22
22
  FPpVCm1zgYSb1v6Qnf3cgXa2f2wYGm17+zAVyIDpwryFru9yF/jJx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/0WV1Ng2/Y6qsHwmqGg2VlYj2h4=
31
32
  -----END CERTIFICATE-----
32
- date: 2013-12-19 00:00:00.000000000 Z
33
+ date: 2014-02-27 00:00:00.000000000 Z
33
34
  dependencies:
34
35
  - !ruby/object:Gem::Dependency
35
36
  name: aws-sdk
metadata.gz.sig CHANGED
Binary file