This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 6f5a5e2  += write_path
6f5a5e2 is described below

commit 6f5a5e2e2d185ee9dd4e62594519b63a6a0cfe81
Author: Sebb <[email protected]>
AuthorDate: Thu Jul 23 16:25:44 2020 +0100

    += write_path
---
 www/secretary/workbench/models/attachment.rb | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/www/secretary/workbench/models/attachment.rb 
b/www/secretary/workbench/models/attachment.rb
index 9daf050..7f274b0 100644
--- a/www/secretary/workbench/models/attachment.rb
+++ b/www/secretary/workbench/models/attachment.rb
@@ -44,12 +44,19 @@ class Attachment
     name.untaint
   end
 
+  # writes the attachment to the specified pathname, which must not exist
+  def write_path(path)
+    File.open(path, File::WRONLY|File::CREAT|File::EXCL, {encoding: 
Encoding::BINARY}) do |file|
+      file.write body
+    end
+  end
+
   # Returns the attachment as an open temporary file
   # Warning: if the reference count goes to 0, the file may be deleted
   # so calling code must retain the reference until done.
   def as_file
     file = SafeTempFile.new([safe_name, '.pdf'])
-    file.write(body)
+    file.write(body) # SafeTempFile forces encoding: BINARY
     file.rewind
     file
   end
@@ -60,7 +67,7 @@ class Attachment
     ext.untaint if ext =~ /^\.\w+$/
 
     file = SafeTempFile.new([safe_name, ext])
-    file.write(body)
+    file.write(body) # SafeTempFile forces encoding: BINARY
     file.rewind
 
     return file if ext == '.pdf'

Reply via email to