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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/s3_meta_sync/version.rb +1 -1
- data/lib/s3_meta_sync.rb +45 -8
- data.tar.gz.sig +0 -0
- metadata +13 -12
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5656a323ca7eaad2a794b645ff158819a2d1edd6
|
4
|
+
data.tar.gz: 47323041dbc94b89b34aa8dc821eb54dd9be3880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b8037f17c549849ab87b37c4587c68cdaaafe70d0532f556dbfd7e30a6f6d9a42ab1d28ffa6668d401e07ecfd2328282b94b366c54e94f3e0d740536e480ce5
|
7
|
+
data.tar.gz: 37130dbe101aa047ad4fdd30163a5cd20754985368eb2db6b4db98d84e72ae2a84e4fad4b99ea64d62d637d04cb89c0c20744ea6aec5c59eb4569079e2a16431
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/s3_meta_sync/version.rb
CHANGED
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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,
|
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.
|
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
|
-
|
13
|
+
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MRAwDgYDVQQDDAdtaWNo
|
14
14
|
YWVsMRcwFQYKCZImiZPyLGQBGRYHZ3Jvc3NlcjESMBAGCgmSJomT8ixkARkWAml0
|
15
|
-
|
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/jJxE38z/DRsd9R
|
23
|
-
/
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
/88CAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFLIj
|
24
|
+
Z1x7SnjGGHK+MiVZkFjjS/iMMB0GA1UdEQQWMBSBEm1pY2hhZWxAZ3Jvc3Nlci5p
|
25
|
+
dDAdBgNVHRIEFjAUgRJtaWNoYWVsQGdyb3NzZXIuaXQwDQYJKoZIhvcNAQEFBQAD
|
26
|
+
ggEBAExBcUWfGuamYn+IddOA0Ws8jUKwB14RXoZRDrTiTAlMm3Bkg2OKyxS3uJXa
|
27
|
+
6Z+LwFiZwVYk62yHXqNzEJycQk4SEmY+xDWLj0p7X6qEeU4QZKwR1TwJ5z3PTrZ6
|
28
|
+
irJgM3q7NIBRvmTzRaAghWcQn+Eyr5YLOfMksjVBMUMnzh5/ZDgq53LphgJbGwvz
|
29
|
+
ScJAgfNclLHnjk9q1mT1s0e1FPWbiAL3siBIR5HpH8qtSEiivTf2ntciebOqS93f
|
30
|
+
F5etKHZg0j3eHO31/i2HnswY04lqGImUu6aM5EnijFTB7PPW2KwKKM4+kKDYFdlw
|
31
|
+
/0WV1Ng2/Y6qsHwmqGg2VlYj2h4=
|
31
32
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
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
|