about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-11-19 08:45:07 +0000
committerEric Wong <normalperson@yhbt.net>2011-11-19 08:45:07 +0000
commitf8156e239ea4da4cbcd020f24bf06c4fb9e7cde7 (patch)
tree31d084283c7e1a9adf98b1754f397c3e7a89f509
parent381044eeda55a5ca7edcccd87d27c30a287723e1 (diff)
downloadmogilefs-client-f8156e239ea4da4cbcd020f24bf06c4fb9e7cde7.tar.gz
Destination path will be created with 0600 permissions to
be consistent with IO.copy_stream [ruby-core:41151]
-rw-r--r--lib/mogilefs/copy_stream.rb6
-rw-r--r--lib/mogilefs/mogilefs.rb4
-rw-r--r--test/test_mogilefs_integration.rb9
3 files changed, 14 insertions, 5 deletions
diff --git a/lib/mogilefs/copy_stream.rb b/lib/mogilefs/copy_stream.rb
index 9397e89..d49112a 100644
--- a/lib/mogilefs/copy_stream.rb
+++ b/lib/mogilefs/copy_stream.rb
@@ -2,9 +2,11 @@
 
 # internal compatibility class for older Rubies
 module MogileFS::CopyStream # :nodoc:
+  @r_args = IO::RDONLY | IO::NOCTTY
+  @w_args = [ IO::WRONLY|IO::CREAT|IO::NOCTTY|IO::TRUNC, 0600 ]
   def self.copy_stream(src, dst)
-    src_io = src.respond_to?(:to_str) ? File.open(src) : src
-    dst_io = dst.respond_to?(:to_str) ? File.open(dst, "w") : dst
+    src_io = src.respond_to?(:to_str) ? File.open(src, @r_args) : src
+    dst_io = dst.respond_to?(:to_str) ? File.open(dst, *@w_args) : dst
     buf = ""
     written = 0
     if src_io.respond_to?(:readpartial)
diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb
index a3d88db..40ee1ca 100644
--- a/lib/mogilefs/mogilefs.rb
+++ b/lib/mogilefs/mogilefs.rb
@@ -22,9 +22,7 @@
 #
 #   # Retrieve the contents of 'my_image' into '/path/to/huge_file'
 #   # without slurping the entire contents into memory:
-#   File.open('/path/to/huge_file', 'w') do |fp|
-#     mg.get_file_data('my_image', fp)
-#   end
+#   mg.get_file_data('my_image', '/path/to/huge_file')
 #
 #   # Remove the key 'my_image' and 'some_key'.
 #   mg.delete('my_image')
diff --git a/test/test_mogilefs_integration.rb b/test/test_mogilefs_integration.rb
index 4bc8e27..18ecd21 100644
--- a/test/test_mogilefs_integration.rb
+++ b/test/test_mogilefs_integration.rb
@@ -14,6 +14,15 @@ class TestMogileFSIntegration < TestMogIntegration
     assert_equal "DAT", @client.get_file_data("CRUD", nil, 3)
     assert_equal "AT", @client.get_file_data("CRUD", nil, 2, 1)
 
+    tmp = Tempfile.new("z")
+    tmp_path = tmp.path
+    tmp.close!
+    assert_equal 4, @client.get_file_data("CRUD", tmp_path)
+    assert_equal "DATA", File.read(tmp_path)
+    st = File.stat(tmp_path)
+    assert_equal 0100600, st.mode
+    File.unlink(tmp_path)
+
     sio = StringIO.new("")
     rv = @client.get_file_data("CRUD", sio)
     assert_equal 4, rv