downspout 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.7
@@ -132,12 +132,18 @@ module Downspout
132
132
  $logger.debug("downspout | downloader | download! | #{self.basename} downloaded? : #{downloaded} ")
133
133
  @finished_at = Time.now
134
134
 
135
- new_name = generate_file_name
135
+ new_name = generate_file_name
136
+
136
137
  if (tf && new_name && !(@basename == new_name)) then
137
138
  # rename file more appropriately
138
139
  $logger.debug("downspout | downloader | download! | Renaming #{@basename} to #{new_name} ...")
139
140
  new_path = File.join( File.dirname( tf.path ), new_name)
140
- FileUtils.mv( tf.path, new_path )
141
+ begin
142
+ FileUtils.mv( tf.path, new_path )
143
+ rescue Exception => e
144
+ $logger.error("downspout | downloader | download! | Exception while renaming #{@basename} : #{e}")
145
+ raise e
146
+ end
141
147
  @path = new_path
142
148
  end
143
149
 
@@ -317,7 +323,11 @@ module Downspout
317
323
  return result
318
324
  end
319
325
 
326
+
327
+ # Extracts filename from Content-Disposition Header per RFC 2183
328
+ # "http://tools.ietf.org/html/rfc2183"
320
329
  def file_name_from_content_disposition
330
+
321
331
  file_name = nil
322
332
 
323
333
  cd_key = response_headers.keys.select{|k| k =~ /content-disposition/i }.first
@@ -326,7 +336,7 @@ module Downspout
326
336
  disposition = @response_headers[cd_key]
327
337
  if disposition then
328
338
  # example : Content-Disposition: attachment; filename="iPad_User_Guide.pdf"
329
- file_name = disposition.match("filename=\"?([^\"]+)\"?")[1]
339
+ file_name = disposition.match("filename=\"?([^;\"]+)\"?")[1]
330
340
  end
331
341
  end
332
342
 
@@ -236,6 +236,11 @@ class DownloaderTest < Test::Unit::TestCase
236
236
  assert_equal "0123456789_X.pdf", @dlx.send("generate_file_name")
237
237
  end
238
238
 
239
+ should "extract the expected file name (followed by size)" do
240
+ @dlx.response_headers["Content-Disposition"].gsub!("0123456789_X.pdf", "2c2afa1c-1b47-422e-bf2d-9848373381bc.pdf;size=5524642")
241
+ assert_equal "2c2afa1c-1b47-422e-bf2d-9848373381bc.pdf", @dlx.send("generate_file_name")
242
+ end
243
+
239
244
  end
240
245
 
241
246
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: downspout
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 6
10
- version: 0.2.6
9
+ - 7
10
+ version: 0.2.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Phi.Sanders
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-30 00:00:00 -04:00
18
+ date: 2011-04-15 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency