paperclip-storage-ftp 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -5
- data/README.md +7 -3
- data/gemfiles/Gemfile.paperclip-4.x +1 -6
- data/lib/paperclip/storage/ftp.rb +24 -20
- data/paperclip-storage-ftp.gemspec +1 -1
- data/spec/integration_spec.rb +23 -23
- data/spec/paperclip/storage/ftp_spec.rb +21 -0
- data/spec/spec_helper.rb +5 -7
- data/test-all.sh +2 -2
- metadata +3 -5
- data/gemfiles/Gemfile.paperclip-2.x +0 -19
- data/gemfiles/Gemfile.paperclip-3.x +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83e3386fa9770427df597a7fd756116877d00ca3
|
4
|
+
data.tar.gz: 50bf907a483309e1ac65ad24156a21b146386346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 509041e1f67837bb53ea17dfca8c19a169053a5535b3d8f2d599221bb8a1bc2798d83e6dd68efe7b37764c1c8e515cf84d93e6855b777ee3a4fcf2c0a870494f
|
7
|
+
data.tar.gz: 03a61d1b2f6a9e0bacf287902174f641adb74a353c55125a71d6977c5fa8b2d7ab0ec3aea039e8c3190edd6afbe7256e9e9067fd1fe51f9e3af98dee3584d1cd
|
data/.travis.yml
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 1.9.3
|
4
3
|
- 2.1
|
4
|
+
- 2.2
|
5
5
|
- jruby-19mode
|
6
|
-
- rbx
|
7
6
|
gemfile:
|
8
|
-
- gemfiles/Gemfile.paperclip-2.x
|
9
|
-
- gemfiles/Gemfile.paperclip-3.x
|
10
7
|
- gemfiles/Gemfile.paperclip-4.x
|
11
8
|
matrix:
|
12
9
|
allow_failures:
|
13
10
|
- rvm: jruby-19mode
|
14
|
-
- rvm: rbx
|
data/README.md
CHANGED
@@ -37,8 +37,7 @@ In your model:
|
|
37
37
|
|
38
38
|
```ruby
|
39
39
|
class User < ActiveRecord::Base
|
40
|
-
has_attached_file :avatar,
|
41
|
-
|
40
|
+
has_attached_file :avatar, {
|
42
41
|
# Choose the FTP storage backend
|
43
42
|
:storage => :ftp,
|
44
43
|
|
@@ -79,11 +78,16 @@ class User < ActiveRecord::Base
|
|
79
78
|
# If set to false and the connection to a particular server cannot be established,
|
80
79
|
# a SystemCallError will be raised (Errno::ETIMEDOUT, Errno::ENETUNREACH, etc.).
|
81
80
|
:ftp_ignore_failing_connections => true # optional, false by default
|
81
|
+
}
|
82
82
|
end
|
83
83
|
```
|
84
84
|
|
85
85
|
## Changelog
|
86
86
|
|
87
|
+
### 1.2.4
|
88
|
+
|
89
|
+
* Avoid unnecessary connection to server(s) when there are no files to be written or deleted [#26](https://github.com/xing/paperclip-storage-ftp/pull/26)
|
90
|
+
|
87
91
|
### 1.2.3
|
88
92
|
|
89
93
|
* Rescue FTPPermError exception during `file_exists?` [#22](https://github.com/xing/paperclip-storage-ftp/pull/22)
|
@@ -124,7 +128,7 @@ Mostly performance enhancements
|
|
124
128
|
|
125
129
|
You can find out more about our work on our [dev blog](http://devblog.xing.com).
|
126
130
|
|
127
|
-
Copyright (c)
|
131
|
+
Copyright (c) 2015 [XING AG](http://www.xing.com)
|
128
132
|
|
129
133
|
Released under the MIT license. For full details see [LICENSE](https://github.com/xing/paperclip-storage-ftp/blob/master/LICENSE)
|
130
134
|
included in this distribution.
|
@@ -8,10 +8,5 @@ group :test do
|
|
8
8
|
gem "sqlite3", :platforms => :ruby
|
9
9
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
10
10
|
|
11
|
-
gem "coveralls", :require => false
|
12
|
-
end
|
13
|
-
|
14
|
-
platforms :rbx do
|
15
|
-
gem 'rubysl', '~> 2.0'
|
16
|
-
gem 'json'
|
11
|
+
gem "coveralls", :require => false, :platforms => :ruby
|
17
12
|
end
|
@@ -35,16 +35,18 @@ module Paperclip
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def flush_writes
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
unless @queued_for_write.empty?
|
39
|
+
with_ftp_servers do |servers|
|
40
|
+
servers.map do |server|
|
41
|
+
Thread.new do
|
42
|
+
@queued_for_write.each do |style_name, file|
|
43
|
+
remote_path = path(style_name)
|
44
|
+
log("saving ftp://#{server.user}@#{server.host}:#{remote_path}")
|
45
|
+
server.put_file(file.path, remote_path)
|
46
|
+
end
|
45
47
|
end
|
46
|
-
end
|
47
|
-
end
|
48
|
+
end.each(&:join)
|
49
|
+
end
|
48
50
|
end
|
49
51
|
|
50
52
|
after_flush_writes # allows attachment to clean up temp files
|
@@ -53,18 +55,20 @@ module Paperclip
|
|
53
55
|
end
|
54
56
|
|
55
57
|
def flush_deletes
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
unless @queued_for_delete.empty?
|
59
|
+
with_ftp_servers do |servers|
|
60
|
+
servers.map do |server|
|
61
|
+
Thread.new do
|
62
|
+
@queued_for_delete.each do |path|
|
63
|
+
log("deleting ftp://#{server.user}@#{server.host}:#{path}")
|
64
|
+
server.delete_file(path)
|
65
|
+
|
66
|
+
log("deleting empty parent directories ftp://#{server.user}@#{server.host}:#{path}")
|
67
|
+
server.rmdir_p(File.dirname(path))
|
68
|
+
end
|
65
69
|
end
|
66
|
-
end
|
67
|
-
end
|
70
|
+
end.each(&:join)
|
71
|
+
end
|
68
72
|
end
|
69
73
|
|
70
74
|
@queued_for_delete = []
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
13
|
gem.name = "paperclip-storage-ftp"
|
14
14
|
gem.require_paths = ["lib"]
|
15
|
-
gem.version = "1.2.
|
15
|
+
gem.version = "1.2.4"
|
16
16
|
|
17
17
|
gem.add_dependency("paperclip")
|
18
18
|
|
data/spec/integration_spec.rb
CHANGED
@@ -30,12 +30,12 @@ describe "paperclip-storage-ftp", :integration => true do
|
|
30
30
|
user.avatar = file
|
31
31
|
user.save!
|
32
32
|
|
33
|
-
File.
|
34
|
-
File.
|
35
|
-
File.
|
36
|
-
File.
|
37
|
-
File.
|
38
|
-
File.
|
33
|
+
File.exist?(uploaded_file_server1).should be true
|
34
|
+
File.exist?(uploaded_file_server1_medium).should be true
|
35
|
+
File.exist?(uploaded_file_server1_thumb).should be true
|
36
|
+
File.exist?(uploaded_file_server2).should be true
|
37
|
+
File.exist?(uploaded_file_server2_medium).should be true
|
38
|
+
File.exist?(uploaded_file_server2_thumb).should be true
|
39
39
|
|
40
40
|
file.size.should == File.size(uploaded_file_server1)
|
41
41
|
file.size.should == File.size(uploaded_file_server2)
|
@@ -47,13 +47,13 @@ describe "paperclip-storage-ftp", :integration => true do
|
|
47
47
|
|
48
48
|
user.destroy
|
49
49
|
|
50
|
-
File.
|
51
|
-
File.
|
52
|
-
File.
|
50
|
+
File.exist?(uploaded_file_server1).should be false
|
51
|
+
File.exist?(uploaded_file_server1_medium).should be false
|
52
|
+
File.exist?(uploaded_file_server1_thumb).should be false
|
53
53
|
|
54
|
-
File.
|
55
|
-
File.
|
56
|
-
File.
|
54
|
+
File.exist?(uploaded_file_server2).should be false
|
55
|
+
File.exist?(uploaded_file_server2_medium).should be false
|
56
|
+
File.exist?(uploaded_file_server2_thumb).should be false
|
57
57
|
end
|
58
58
|
|
59
59
|
it "removes empty parent directories after image deletion" do
|
@@ -62,8 +62,8 @@ describe "paperclip-storage-ftp", :integration => true do
|
|
62
62
|
|
63
63
|
user.destroy
|
64
64
|
|
65
|
-
Dir.
|
66
|
-
Dir.
|
65
|
+
Dir.exist?(File.dirname(uploaded_file_server1)).should be false
|
66
|
+
Dir.exist?(File.dirname(uploaded_file_server2)).should be false
|
67
67
|
end
|
68
68
|
|
69
69
|
it "does not remove parent directories which are not empty" do
|
@@ -74,7 +74,7 @@ describe "paperclip-storage-ftp", :integration => true do
|
|
74
74
|
|
75
75
|
user.destroy
|
76
76
|
|
77
|
-
File.
|
77
|
+
File.exist?(uploaded_file_server1_other).should be true
|
78
78
|
end
|
79
79
|
|
80
80
|
it "survives temporarily closed ftp connections" do
|
@@ -89,8 +89,8 @@ describe "paperclip-storage-ftp", :integration => true do
|
|
89
89
|
user.avatar = file
|
90
90
|
user.save!
|
91
91
|
|
92
|
-
File.
|
93
|
-
File.
|
92
|
+
File.exist?(uploaded_file_server1).should be true
|
93
|
+
File.exist?(uploaded_file_server2).should be true
|
94
94
|
end
|
95
95
|
|
96
96
|
it "allows ignoring failed connections" do
|
@@ -98,12 +98,12 @@ describe "paperclip-storage-ftp", :integration => true do
|
|
98
98
|
user.avatar = file
|
99
99
|
expect{ user.save! }.to_not raise_error
|
100
100
|
|
101
|
-
File.
|
102
|
-
File.
|
103
|
-
File.
|
104
|
-
File.
|
105
|
-
File.
|
106
|
-
File.
|
101
|
+
File.exist?(uploaded_file_server1).should be true
|
102
|
+
File.exist?(uploaded_file_server1_medium).should be true
|
103
|
+
File.exist?(uploaded_file_server1_thumb).should be true
|
104
|
+
File.exist?(uploaded_file_server2).should be false
|
105
|
+
File.exist?(uploaded_file_server2_medium).should be false
|
106
|
+
File.exist?(uploaded_file_server2_thumb).should be false
|
107
107
|
end
|
108
108
|
|
109
109
|
it "raises a SystemCallError when not ignoring failed connections" do
|
@@ -80,6 +80,17 @@ describe Paperclip::Storage::Ftp do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
context "#flush_writes" do
|
83
|
+
it "doesn't connect to the servers if there is nothing to write" do
|
84
|
+
attachment.instance_variable_set(:@queued_for_write, {})
|
85
|
+
|
86
|
+
attachment.should_not_receive(:with_ftp_servers)
|
87
|
+
attachment.should_receive(:after_flush_writes).with(no_args)
|
88
|
+
|
89
|
+
attachment.flush_writes
|
90
|
+
|
91
|
+
attachment.queued_for_write.should == {}
|
92
|
+
end
|
93
|
+
|
83
94
|
it "stores the files on every server" do
|
84
95
|
original_file = double("original_file", :path => "/tmp/original/foo.jpg")
|
85
96
|
thumb_file = double("thumb_file", :path => "/tmp/thumb/foo.jpg")
|
@@ -105,6 +116,16 @@ describe Paperclip::Storage::Ftp do
|
|
105
116
|
end
|
106
117
|
|
107
118
|
context "#flush_deletes" do
|
119
|
+
it "doesn't connect to the servers if there is nothing to delete" do
|
120
|
+
attachment.instance_variable_set(:@queued_for_delete, [])
|
121
|
+
|
122
|
+
attachment.should_not_receive(:with_ftp_servers)
|
123
|
+
|
124
|
+
attachment.flush_deletes
|
125
|
+
|
126
|
+
attachment.instance_variable_get(:@queued_for_delete).should == []
|
127
|
+
end
|
128
|
+
|
108
129
|
it "deletes the files on every server" do
|
109
130
|
attachment.instance_variable_set(:@queued_for_delete, [
|
110
131
|
"/files/original/foo.jpg",
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
|
2
|
-
require "coveralls"
|
3
|
-
|
4
|
-
|
5
|
-
SimpleCov.start do
|
6
|
-
add_filter "spec"
|
1
|
+
begin
|
2
|
+
require "coveralls"
|
3
|
+
Coveralls.wear!
|
4
|
+
rescue LoadError
|
7
5
|
end
|
8
6
|
|
9
7
|
RSpec.configure do |config|
|
@@ -22,5 +20,5 @@ require "paperclip/storage/ftp"
|
|
22
20
|
|
23
21
|
Paperclip.options[:log] = false
|
24
22
|
|
25
|
-
# https://github.com/thoughtbot/cocaine#
|
23
|
+
# https://github.com/thoughtbot/cocaine#caveat
|
26
24
|
Cocaine::CommandLine.runner = Cocaine::CommandLine::BackticksRunner.new
|
data/test-all.sh
CHANGED
@@ -14,13 +14,13 @@ else
|
|
14
14
|
printf "ERROR: An RVM installation was not found.\n"
|
15
15
|
fi
|
16
16
|
|
17
|
-
for ruby in '1
|
17
|
+
for ruby in '2.1' '2.2' 'jruby --1.9'
|
18
18
|
do
|
19
19
|
rvm try_install $ruby
|
20
20
|
rvm use $ruby
|
21
21
|
gem install bundler --conservative --no-rdoc --no-ri
|
22
22
|
|
23
|
-
for paperclip_version in
|
23
|
+
for paperclip_version in 4
|
24
24
|
do
|
25
25
|
gemfile="gemfiles/Gemfile.paperclip-${paperclip_version}.x"
|
26
26
|
bundle install --gemfile=$gemfile
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-storage-ftp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Röbke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paperclip
|
@@ -93,8 +93,6 @@ files:
|
|
93
93
|
- LICENSE
|
94
94
|
- README.md
|
95
95
|
- Rakefile
|
96
|
-
- gemfiles/Gemfile.paperclip-2.x
|
97
|
-
- gemfiles/Gemfile.paperclip-3.x
|
98
96
|
- gemfiles/Gemfile.paperclip-4.x
|
99
97
|
- lib/paperclip/storage/ftp.rb
|
100
98
|
- lib/paperclip/storage/ftp/server.rb
|
@@ -157,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
155
|
version: '0'
|
158
156
|
requirements: []
|
159
157
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.
|
158
|
+
rubygems_version: 2.4.5
|
161
159
|
signing_key:
|
162
160
|
specification_version: 4
|
163
161
|
summary: Allow Paperclip attachments to be stored on FTP servers
|
@@ -1,19 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
gemspec :path => '..'
|
4
|
-
|
5
|
-
gem "paperclip", "~>2.0"
|
6
|
-
|
7
|
-
group :test do
|
8
|
-
gem "activerecord", "~>3.0"
|
9
|
-
|
10
|
-
gem "sqlite3", :platforms => :ruby
|
11
|
-
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
12
|
-
|
13
|
-
gem "coveralls", :require => false
|
14
|
-
end
|
15
|
-
|
16
|
-
platforms :rbx do
|
17
|
-
gem 'rubysl', '~> 2.0'
|
18
|
-
gem 'json'
|
19
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
gemspec :path => '..'
|
4
|
-
|
5
|
-
gem "paperclip", "~>3.0"
|
6
|
-
|
7
|
-
group :test do
|
8
|
-
gem "sqlite3", :platforms => :ruby
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
10
|
-
|
11
|
-
gem "coveralls", :require => false
|
12
|
-
end
|
13
|
-
|
14
|
-
platforms :rbx do
|
15
|
-
gem 'rubysl', '~> 2.0'
|
16
|
-
gem 'json'
|
17
|
-
end
|