olek-paperclipftp 0.1.0.6 → 0.1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/paperclipftp.rb +32 -28
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.0.
|
1
|
+
0.1.0.7
|
data/lib/paperclipftp.rb
CHANGED
@@ -9,7 +9,8 @@ module Paperclip
|
|
9
9
|
@ftp_credentials = parse_credentials(@options[:ftp_credentials])
|
10
10
|
@passive_mode = !!@options[:ftp_passive_mode]
|
11
11
|
@debug_mode = !!@options[:ftp_debug_mode]
|
12
|
-
@
|
12
|
+
@verify_size = !!@options[:ftp_verify_size_on_upload]
|
13
|
+
@timeout = @options[:ftp_timeout] || 3600
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
@@ -46,14 +47,26 @@ module Paperclip
|
|
46
47
|
@queued_for_write.each do |style, file|
|
47
48
|
Timeout::timeout(@timeout, FtpTimeout) do
|
48
49
|
file.close
|
49
|
-
# avoiding those weird occasional 0 file sizes by not using instance method file.size
|
50
|
-
local_file_size = File.size(file.path)
|
51
50
|
remote_path = ftp_path(style)
|
52
|
-
ensure_parent_folder_for(remote_path)
|
53
51
|
log("uploading #{remote_path}")
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
first_try = true
|
53
|
+
begin
|
54
|
+
ftp.putbinaryfile(file.path, remote_path)
|
55
|
+
rescue Net::FTPPermError => e
|
56
|
+
if first_try
|
57
|
+
first_try = false
|
58
|
+
ensure_parent_folder_for(remote_path)
|
59
|
+
retry
|
60
|
+
else
|
61
|
+
raise e
|
62
|
+
end
|
63
|
+
end
|
64
|
+
if @verify_size
|
65
|
+
# avoiding those weird occasional 0 file sizes by not using instance method file.size
|
66
|
+
local_file_size = File.size(file.path)
|
67
|
+
remote_file_size = file_size(remote_path)
|
68
|
+
raise Net::FTPError.new "Uploaded #{remote_file_size} bytes instead of #{local_file_size} bytes" unless remote_file_size == local_file_size
|
69
|
+
end
|
57
70
|
end
|
58
71
|
end
|
59
72
|
@queued_for_write = {}
|
@@ -88,28 +101,19 @@ module Paperclip
|
|
88
101
|
|
89
102
|
def ensure_parent_folder_for(remote_path)
|
90
103
|
dir_path = File.dirname(remote_path)
|
91
|
-
|
104
|
+
ftp.chdir("/")
|
105
|
+
dir_path.split(File::SEPARATOR).each do |rdir|
|
106
|
+
next if rdir.blank?
|
107
|
+
first_time = true
|
92
108
|
begin
|
93
|
-
ftp.chdir(
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
next if rdir.blank?
|
102
|
-
first_time = true
|
103
|
-
begin
|
104
|
-
ftp.chdir(rdir)
|
105
|
-
rescue Net::FTPPermError => e
|
106
|
-
if first_time
|
107
|
-
ftp.mkdir(rdir)
|
108
|
-
first_time = false
|
109
|
-
retry
|
110
|
-
else
|
111
|
-
raise e
|
112
|
-
end
|
109
|
+
ftp.chdir(rdir)
|
110
|
+
rescue Net::FTPPermError => e
|
111
|
+
if first_time
|
112
|
+
ftp.mkdir(rdir)
|
113
|
+
first_time = false
|
114
|
+
retry
|
115
|
+
else
|
116
|
+
raise e
|
113
117
|
end
|
114
118
|
end
|
115
119
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: olek-paperclipftp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 73
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 0.1.0.
|
10
|
+
- 7
|
11
|
+
version: 0.1.0.7
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Damian Caruso
|