smart_s3_sync 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/s5 +13 -4
- data/lib/smart_s3_sync.rb +2 -2
- data/lib/smart_s3_sync/file_table.rb +2 -2
- data/lib/smart_s3_sync/file_target.rb +14 -9
- data/lib/smart_s3_sync/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14666867e372ebd1ca9f50414a68f497d84fe1d4
|
4
|
+
data.tar.gz: a650d738ab17f11d126b11ea54b4f6e1ced3398c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1341e63a50e8d14192964a78514fdba32262fc304ca0951cf99b23b6b7a5820d129966f01835166f76065c3fda76179aaacad56f5e138b624a698de7996b79a
|
7
|
+
data.tar.gz: 62a25fa9228c46df83961d11aa3265138ab9798e52f3276a9fe5fac460ff8866ca38173068db441ef9050c2d1754e95756150a29839d95adcf02027d4731b5f6
|
data/bin/s5
CHANGED
@@ -8,11 +8,11 @@ def quit(message)
|
|
8
8
|
exit 1
|
9
9
|
end
|
10
10
|
|
11
|
-
if ARGV.length
|
12
|
-
quit "Usage: #{File.basename($0)} REMOTE_URI LOCAL_DIR"
|
11
|
+
if ARGV.length < 2
|
12
|
+
quit "Usage: #{File.basename($0)} REMOTE_URI LOCAL_DIR [options]"
|
13
13
|
end
|
14
14
|
|
15
|
-
remote_uri, local_dir = ARGV
|
15
|
+
remote_uri, local_dir = ARGV[0], ARGV[1]
|
16
16
|
|
17
17
|
remote_uri = URI.parse(remote_uri)
|
18
18
|
|
@@ -33,8 +33,17 @@ if !(access_key_id && access_key_secret)
|
|
33
33
|
quit "S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY environment variables are required"
|
34
34
|
end
|
35
35
|
|
36
|
+
options = {}
|
37
|
+
|
38
|
+
if ARGV.length > 2
|
39
|
+
ARGV[2, ARGV.length-2].each do |opt|
|
40
|
+
name, val = opt.split('=', 2)
|
41
|
+
options[name.sub(/^--/, '')] = val
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
36
45
|
SmartS3Sync.sync(local_dir, bucket, {
|
37
46
|
provider: 'AWS',
|
38
47
|
aws_access_key_id: access_key_id,
|
39
48
|
aws_secret_access_key: access_key_secret
|
40
|
-
}, prefix)
|
49
|
+
}, prefix, options)
|
data/lib/smart_s3_sync.rb
CHANGED
@@ -6,7 +6,7 @@ Fog.credentials = { :path_style => true }
|
|
6
6
|
|
7
7
|
module SmartS3Sync
|
8
8
|
|
9
|
-
def self.sync(dir, remote_dir, connection_options, remote_prefix=nil)
|
9
|
+
def self.sync(dir, remote_dir, connection_options, remote_prefix=nil, sync_options={})
|
10
10
|
table = FileTable.new(dir, remote_prefix)
|
11
11
|
|
12
12
|
bucket = Fog::Storage.new(connection_options).directories.
|
@@ -32,7 +32,7 @@ module SmartS3Sync
|
|
32
32
|
$stderr.puts "Status: with an effective total of #{table.to_copy.inject(0){|coll, obj| coll + obj.destinations.length }} files (#{table.to_copy.map{|x| x.size * x.destinations.length }.inject(&:+)} bytes)"
|
33
33
|
|
34
34
|
# And copy them to the right places
|
35
|
-
table.copy!(bucket)
|
35
|
+
table.copy!(bucket, sync_options)
|
36
36
|
|
37
37
|
# sweep through and remove all files not in the cloud
|
38
38
|
Dir.glob(File.join(dir, '**/*')) do |file|
|
@@ -17,13 +17,13 @@ module SmartS3Sync
|
|
17
17
|
@map[digest].add_destination(destination_filename) # and add local path to the target
|
18
18
|
end
|
19
19
|
|
20
|
-
def copy!(fog_dir)
|
20
|
+
def copy!(fog_dir, sync_options={})
|
21
21
|
@map.sort_by do |(k, target)|
|
22
22
|
1_000_000_000 * (target.local_source.nil? ? 0 : -1) -
|
23
23
|
1_000_000 * target.destinations.length +
|
24
24
|
1/1_048_576 * target.size
|
25
25
|
end.each do |(k, target)|
|
26
|
-
target.copy!(fog_dir)
|
26
|
+
target.copy!(fog_dir, sync_options)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -26,33 +26,33 @@ module SmartS3Sync
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def copy!(fog_dir)
|
29
|
+
def copy!(fog_dir, sync_options={})
|
30
30
|
# If every copy in the cloud is already present, the
|
31
31
|
# number of destinations will be 0 - there is no work
|
32
32
|
# left to do.
|
33
33
|
if destinations.length > 0
|
34
34
|
if local_source.nil? # we prefer to not have to download
|
35
|
-
copy_from_fog(fog_dir)
|
35
|
+
copy_from_fog(fog_dir, sync_options)
|
36
36
|
else
|
37
|
-
copy_from_local(local_source)
|
37
|
+
copy_from_local(local_source, sync_options)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
43
43
|
|
44
|
-
def copy_from_fog(fog_dir)
|
44
|
+
def copy_from_fog(fog_dir, sync_options={})
|
45
45
|
$stderr.puts "Downloading #{remote_filename}"
|
46
46
|
tries = 0
|
47
47
|
file = nil
|
48
48
|
begin
|
49
|
-
file = download(fog_dir) # basically, just try.
|
49
|
+
file = download(fog_dir, sync_options) # basically, just try.
|
50
50
|
|
51
51
|
if file_hash(file.path) != digest.to_s
|
52
52
|
raise "Hash mismatch downloading #{remote_filename}"
|
53
53
|
end
|
54
54
|
|
55
|
-
copy_from_local(file.path) # with a copy locally, the job is the same
|
55
|
+
copy_from_local(file.path, sync_options) # with a copy locally, the job is the same
|
56
56
|
@local_source = destinations.shift # we now have a local copy!
|
57
57
|
rescue StandardError => e
|
58
58
|
if tries < 5
|
@@ -68,7 +68,7 @@ module SmartS3Sync
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
def copy_from_local(source)
|
71
|
+
def copy_from_local(source, sync_options={})
|
72
72
|
$stderr.puts "Linking #{destinations.join(', ')}"
|
73
73
|
destinations.each do |dest|
|
74
74
|
FileUtils.mkdir_p(File.dirname(dest), :mode => 0755)
|
@@ -89,11 +89,11 @@ module SmartS3Sync
|
|
89
89
|
DigestCache.digest(path)
|
90
90
|
end
|
91
91
|
|
92
|
-
def download(fog_dir)
|
92
|
+
def download(fog_dir, sync_options={})
|
93
93
|
dir = File.dirname(destinations[0])
|
94
94
|
FileUtils.mkdir_p(dir)
|
95
95
|
Tempfile.new(".#{digest}", dir).tap do |file|
|
96
|
-
fog_dir.files.get(remote_filename) do |chunk, left, total|
|
96
|
+
rfile = fog_dir.files.get(remote_filename) do |chunk, left, total|
|
97
97
|
if (chunk.size + left == total) # fog might restart in the middle
|
98
98
|
file.rewind
|
99
99
|
end
|
@@ -102,6 +102,11 @@ module SmartS3Sync
|
|
102
102
|
end
|
103
103
|
file.close
|
104
104
|
File.chmod(0644, file.path)
|
105
|
+
if sync_options.has_key?('set-timestamp-from-metadata')
|
106
|
+
time = rfile.metadata[sync_options['set-timestamp-from-metadata']]
|
107
|
+
time &&= Time.at(time.to_i)
|
108
|
+
time && File.utime(time, time, file)
|
109
|
+
end
|
105
110
|
end
|
106
111
|
end
|
107
112
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_s3_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Rhoden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09
|
11
|
+
date: 2014-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|