closync 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +4 -0
- data/lib/closync/sync.rb +25 -26
- data/lib/closync/version.rb +1 -1
- data/spec/lib/closync/sync_spec.rb +48 -14
- data/spec/lib/closync/version_spec.rb +1 -1
- metadata +5 -4
data/Changelog.md
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
## 0.1.0 (2012-10-23)
|
2
|
+
|
3
|
+
* new feature: files that do not appear in the origin bucket are now automatically deleted from the destination bucket
|
4
|
+
* enhancement: to save bandwidth and reduce the number of PUT requests, only stale files are copied from origin to destination bucket
|
data/lib/closync/sync.rb
CHANGED
@@ -12,43 +12,42 @@ module Closync
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def push!
|
15
|
-
|
16
|
-
|
15
|
+
@local.directory.files.each do |local_file|
|
16
|
+
upload!(local_file) if stale_on_remote?(local_file)
|
17
|
+
end
|
18
|
+
@remote.directory.files.each do |remote_file|
|
19
|
+
remote_file.destroy unless exists_locally?(remote_file)
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
private
|
20
24
|
|
21
|
-
def push_new_data!
|
22
|
-
@local.directory.files.each do |file|
|
23
|
-
upload!(file) if upload?(file)
|
24
|
-
end
|
25
|
-
end
|
26
25
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
# end
|
26
|
+
def exists_locally?(remote_file)
|
27
|
+
return true if @local.directory.files.head(remote_file.key)
|
28
|
+
false
|
31
29
|
end
|
32
30
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
31
|
+
# TODO(wenzowski): local_file.should.respond_to?(:content_md5)
|
32
|
+
def stale_on_remote?(local_file)
|
33
|
+
remote_file = @remote.directory.files.head(local_file.key)
|
34
|
+
return true unless remote_file # file is missing from remote, therefore stale
|
35
|
+
if remote_file.respond_to?(:content_md5) && local_file.respond_to?(:content_md5)
|
36
|
+
(
|
37
|
+
( remote_file.content_length != local_file.content_length ) &&
|
38
|
+
( remote_file.content_md5 != local_file.content_md5 )
|
39
|
+
)
|
40
|
+
else
|
41
|
+
( remote_file.content_length != local_file.content_length )
|
42
|
+
end
|
44
43
|
end
|
45
44
|
|
46
45
|
# If file already exists on remote it will be overwritten.
|
47
|
-
def upload!(
|
46
|
+
def upload!(local_file)
|
48
47
|
@remote.directory.files.create(
|
49
|
-
key:
|
50
|
-
body:
|
51
|
-
cache_control: "public, max-age=#{max_age(
|
48
|
+
key: local_file.key,
|
49
|
+
body: local_file.body,
|
50
|
+
cache_control: "public, max-age=#{max_age(local_file)}",
|
52
51
|
public: true
|
53
52
|
)
|
54
53
|
end
|
data/lib/closync/version.rb
CHANGED
@@ -15,27 +15,61 @@ describe Closync::Storage do
|
|
15
15
|
config
|
16
16
|
}
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
before(:each) do
|
19
|
+
FileUtils.mkdir_p local_dir
|
20
|
+
FileUtils.mkdir_p remote_dir
|
21
|
+
FileUtils.touch "#{remote_dir}/missing.html"
|
22
|
+
FileUtils.touch "#{remote_dir}/stale.html"
|
23
|
+
FileUtils.touch "#{local_dir}/index.html"
|
24
|
+
FileUtils.touch "#{local_dir}/pic.jpg"
|
25
|
+
File.open("#{local_dir}/stale.html", 'w') {|f| f.write('new data') }
|
26
|
+
end
|
27
|
+
after(:each) do
|
28
|
+
FileUtils.rm_rf local_dir
|
29
|
+
FileUtils.rm_rf remote_dir
|
30
|
+
end
|
29
31
|
|
30
|
-
|
32
|
+
it { lambda {Closync::Sync.new(config)}.should_not raise_error }
|
31
33
|
|
32
|
-
|
34
|
+
context 'before sync' do
|
35
|
+
its 'new files exist locally' do
|
36
|
+
File.exists?("#{local_dir}/index.html").should be_true
|
37
|
+
File.exists?("#{local_dir}/pic.jpg").should be_true
|
38
|
+
end
|
39
|
+
its 'new files do not exist on remote' do
|
33
40
|
File.exists?("#{remote_dir}/index.html").should be_false
|
34
41
|
File.exists?("#{remote_dir}/pic.jpg").should be_false
|
35
|
-
|
42
|
+
end
|
43
|
+
its 'missing files do not exist locally' do
|
44
|
+
File.exists?("#{local_dir}/missing.html").should be_false
|
45
|
+
end
|
46
|
+
its 'missing files exist on remote' do
|
47
|
+
File.exists?("#{remote_dir}/missing.html").should be_true
|
48
|
+
end
|
49
|
+
its 'stale files are a different size on remote' do
|
50
|
+
File.size("#{remote_dir}/stale.html").should_not == File.size("#{local_dir}/stale.html")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'after sync' do
|
55
|
+
before(:each) { Closync::Sync.new(config).push! }
|
56
|
+
its 'new files exist locally' do
|
57
|
+
File.exists?("#{local_dir}/index.html").should be_true
|
58
|
+
File.exists?("#{local_dir}/pic.jpg").should be_true
|
59
|
+
end
|
60
|
+
its 'new files exist on remote' do
|
36
61
|
File.exists?("#{remote_dir}/index.html").should be_true
|
37
62
|
File.exists?("#{remote_dir}/pic.jpg").should be_true
|
38
63
|
end
|
64
|
+
its 'missing files do not exist locally' do
|
65
|
+
File.exists?("#{local_dir}/missing.html").should be_false
|
66
|
+
end
|
67
|
+
its 'missing files do not exist on remote' do
|
68
|
+
File.exists?("#{remote_dir}/missing.html").should be_false
|
69
|
+
end
|
70
|
+
its 'stale files are the same size on remote' do
|
71
|
+
File.size("#{remote_dir}/stale.html").should == File.size("#{local_dir}/stale.html")
|
72
|
+
end
|
39
73
|
end
|
40
74
|
|
41
75
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: closync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- .gitignore
|
40
40
|
- .rspec
|
41
41
|
- .travis.yml
|
42
|
+
- Changelog.md
|
42
43
|
- Gemfile
|
43
44
|
- Guardfile
|
44
45
|
- LICENSE
|
@@ -71,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
72
|
version: '0'
|
72
73
|
segments:
|
73
74
|
- 0
|
74
|
-
hash:
|
75
|
+
hash: 12197200572235269
|
75
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
77
|
none: false
|
77
78
|
requirements:
|
@@ -80,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
81
|
version: '0'
|
81
82
|
segments:
|
82
83
|
- 0
|
83
|
-
hash:
|
84
|
+
hash: 12197200572235269
|
84
85
|
requirements: []
|
85
86
|
rubyforge_project:
|
86
87
|
rubygems_version: 1.8.24
|