diff options
-rw-r--r-- | lib/mogilefs/http_file.rb | 24 | ||||
-rw-r--r-- | test/test_mogilefs_integration.rb | 13 |
2 files changed, 25 insertions, 12 deletions
diff --git a/lib/mogilefs/http_file.rb b/lib/mogilefs/http_file.rb index b3a664f..b2d5620 100644 --- a/lib/mogilefs/http_file.rb +++ b/lib/mogilefs/http_file.rb @@ -101,20 +101,20 @@ class MogileFS::HTTPFile < StringIO if @streaming_io file_size = put_streaming_io(sock, uri) elsif @big_io - if String === @big_io || @big_io.respond_to?(:to_path) - file = @big_io.respond_to?(:stat) ? @big_io : File.open(@big_io) + stat = file = size = nil + if @big_io.respond_to?(:stat) + stat = @big_io.stat + elsif String === @big_io || @big_io.respond_to?(:to_path) + file = File.open(@big_io) stat = file.stat - file_size = request_put(sock, uri, stat.file? ? stat.size : nil, file) - else - size = nil - if @big_io.respond_to?(:stat) - stat = @big_io.stat - size = stat.size if stat.file? - elsif @big_io.respond_to?(:size) - size = @big_io.size - end - file_size = request_put(sock, uri, size, @big_io) + elsif @big_io.respond_to?(:size) + size = @big_io.size end + if stat && stat.file? + size ||= stat.size + file ||= @big_io.to_io if @big_io.respond_to?(:to_io) + end + file_size = request_put(sock, uri, size, file || @big_io) else rewind request_put(sock, uri, file_size, self) diff --git a/test/test_mogilefs_integration.rb b/test/test_mogilefs_integration.rb index 88657a9..b6a181a 100644 --- a/test/test_mogilefs_integration.rb +++ b/test/test_mogilefs_integration.rb @@ -269,4 +269,17 @@ class TestMogileFSIntegration < TestMogIntegration assert_equal true, checked, "expect_md5 lambda called" end + + def test_store_file_unlinked_tempfile + tmp = Tempfile.new("store_file_unlinked") + tmp.unlink + tmp.sync = true + tmp.write "HIHI" + tmp.rewind + assert_nothing_raised do + @client.store_file("unlinked", nil, tmp) + end + + assert_equal "HIHI", @client.get_file_data("unlinked") + end end |