smart_s3_sync 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/smart_s3_sync.rb +12 -3
- data/lib/smart_s3_sync/file_table.rb +6 -2
- data/lib/smart_s3_sync/file_target.rb +5 -4
- data/lib/smart_s3_sync/version.rb +1 -1
- metadata +1 -2
- data/Gemfile.lock +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a368a353c21091f1acd3cfd2db6292e5f3ccdd8c
|
4
|
+
data.tar.gz: 1be713c432e980985fa5fd455fcfa71c1bce9d6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af6620d81c194070e162ce3a2d54241ca37d81a7676f58cc5d819c5fc22f6f8ef86f154476b2b969b66d8288ffe2986a7c617abfc1c9814eb2be3156c7126baf
|
7
|
+
data.tar.gz: faa3a79b469b21523181d7aaa3e293e71068d41b515d62cb80458fca7a2f923e0e44cb0ebb3eec128d2e15cb5ea3b16f4b891ccb496192151776a82857c8c6ae
|
data/.gitignore
CHANGED
data/lib/smart_s3_sync.rb
CHANGED
@@ -13,9 +13,17 @@ module SmartS3Sync
|
|
13
13
|
get(remote_dir, {:prefix => remote_prefix})
|
14
14
|
|
15
15
|
# Add all files in the cloud to our map.
|
16
|
-
|
16
|
+
print "Checking Files: 0"
|
17
|
+
checked = 0
|
18
|
+
bucket.files.each do |file|
|
19
|
+
table.push(file)
|
20
|
+
print "\b" * checked.to_s.length
|
21
|
+
print (checked += 1).to_s
|
22
|
+
end
|
17
23
|
|
18
|
-
puts "
|
24
|
+
puts "\n"
|
25
|
+
puts "Status: Need to download #{table.to_download.length} files (#{table.to_download.map(&:size).inject(&:+)} bytes)"
|
26
|
+
puts "Status: with an effective total of #{table.to_copy.length} files (#{table.to_copy.map{|x| x.size * x.destinations.length }.inject(&:+)} bytes)"
|
19
27
|
|
20
28
|
# And copy them to the right places
|
21
29
|
table.copy!(bucket)
|
@@ -23,13 +31,14 @@ module SmartS3Sync
|
|
23
31
|
# sweep through and remove all files not in the cloud
|
24
32
|
Dir[File.join(dir, '**/*')].each do |file|
|
25
33
|
if !File.directory?(file)
|
26
|
-
File.unlink(file) unless table.keep?(file)
|
34
|
+
File.unlink(file) and puts "DELETING: #{file}" unless table.keep?(file)
|
27
35
|
end
|
28
36
|
end
|
29
37
|
|
30
38
|
# and then all empty directories
|
31
39
|
Dir[File.join(dir, '**/*')].each do |file|
|
32
40
|
if File.directory?(file) && Dir.entries(file).length == 0
|
41
|
+
puts "DELETING: #{file}"
|
33
42
|
Dir.rmdir(file)
|
34
43
|
end
|
35
44
|
end
|
@@ -11,7 +11,7 @@ module SmartS3Sync
|
|
11
11
|
|
12
12
|
def push(fog_file)
|
13
13
|
digest = hash_key(fog_file) # pull cloud calculated hex digest from file
|
14
|
-
@map[digest] ||= FileTarget.new(digest, fog_file.key) # grab or create target
|
14
|
+
@map[digest] ||= FileTarget.new(digest, fog_file.key, fog_file.content_length) # grab or create target
|
15
15
|
destination_filename = File.expand_path(strip_prefix(fog_file.key), @root) # calculate local path
|
16
16
|
@files.push destination_filename # add local path to global list of files to keep
|
17
17
|
@map[digest].add_destination(destination_filename) # and add local path to the target
|
@@ -28,7 +28,11 @@ module SmartS3Sync
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def to_copy
|
31
|
-
@map.
|
31
|
+
@_tc ||= @map.select {|key, target| target.destinations.length > 0 }.map{|x, y| y }
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_download
|
35
|
+
@_td ||= to_copy.select {|target| target.local_source.nil? }
|
32
36
|
end
|
33
37
|
|
34
38
|
private
|
@@ -3,10 +3,11 @@ require 'smart_s3_sync/digest_cache'
|
|
3
3
|
|
4
4
|
module SmartS3Sync
|
5
5
|
class FileTarget
|
6
|
-
attr_reader :digest, :remote_filename, :local_source, :destinations
|
6
|
+
attr_reader :digest, :remote_filename, :local_source, :destinations, :size
|
7
7
|
|
8
|
-
def initialize(digest, remote_filename)
|
8
|
+
def initialize(digest, remote_filename, size)
|
9
9
|
@digest = digest
|
10
|
+
@size = size
|
10
11
|
@remote_filename = remote_filename
|
11
12
|
@local_source = nil
|
12
13
|
@destinations = []
|
@@ -41,7 +42,7 @@ module SmartS3Sync
|
|
41
42
|
private
|
42
43
|
|
43
44
|
def copy_from_fog(fog_dir)
|
44
|
-
puts "Downloading #{remote_filename}
|
45
|
+
puts "Downloading #{remote_filename}"
|
45
46
|
tries = 0
|
46
47
|
file = nil
|
47
48
|
begin
|
@@ -68,7 +69,7 @@ module SmartS3Sync
|
|
68
69
|
end
|
69
70
|
|
70
71
|
def copy_from_local(source)
|
71
|
-
puts "
|
72
|
+
puts "Linking #{destinations.join(', ')}"
|
72
73
|
destinations.each do |dest|
|
73
74
|
FileUtils.mkdir_p(File.dirname(dest))
|
74
75
|
FileUtils.ln(source, dest, :force => true)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Rhoden
|
@@ -76,7 +76,6 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- .gitignore
|
78
78
|
- Gemfile
|
79
|
-
- Gemfile.lock
|
80
79
|
- LICENSE.txt
|
81
80
|
- README.md
|
82
81
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
smart_s3_sync (0.0.5)
|
5
|
-
fog
|
6
|
-
sqlite3
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
builder (3.2.2)
|
12
|
-
excon (0.37.0)
|
13
|
-
fog (1.22.1)
|
14
|
-
fog-brightbox
|
15
|
-
fog-core (~> 1.22)
|
16
|
-
fog-json
|
17
|
-
ipaddress (~> 0.5)
|
18
|
-
nokogiri (~> 1.5, >= 1.5.11)
|
19
|
-
fog-brightbox (0.1.1)
|
20
|
-
fog-core (~> 1.22)
|
21
|
-
fog-json
|
22
|
-
inflecto
|
23
|
-
fog-core (1.22.0)
|
24
|
-
builder
|
25
|
-
excon (~> 0.33)
|
26
|
-
formatador (~> 0.2)
|
27
|
-
mime-types
|
28
|
-
net-scp (~> 1.1)
|
29
|
-
net-ssh (>= 2.1.3)
|
30
|
-
fog-json (1.0.0)
|
31
|
-
multi_json (~> 1.0)
|
32
|
-
formatador (0.2.5)
|
33
|
-
inflecto (0.0.2)
|
34
|
-
ipaddress (0.8.0)
|
35
|
-
mime-types (2.3)
|
36
|
-
mini_portile (0.6.0)
|
37
|
-
multi_json (1.10.1)
|
38
|
-
net-scp (1.2.1)
|
39
|
-
net-ssh (>= 2.6.5)
|
40
|
-
net-ssh (2.9.1)
|
41
|
-
nokogiri (1.6.2.1)
|
42
|
-
mini_portile (= 0.6.0)
|
43
|
-
rake (10.3.2)
|
44
|
-
sqlite3 (1.3.9)
|
45
|
-
|
46
|
-
PLATFORMS
|
47
|
-
ruby
|
48
|
-
|
49
|
-
DEPENDENCIES
|
50
|
-
bundler (~> 1.3)
|
51
|
-
rake
|
52
|
-
smart_s3_sync!
|