You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2021/11/04 01:38:44 UTC

[whimsy] branch master updated: No longer needed

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 b595deb  No longer needed
b595deb is described below

commit b595debdad4ce11c6bc93b1050a8e3f01296ebcc
Author: Sebb <se...@apache.org>
AuthorDate: Thu Nov 4 01:38:37 2021 +0000

    No longer needed
---
 www/secretary/workbench/models/attachment.rb       | 12 +++++-----
 www/secretary/workbench/models/safetemp.rb         | 28 ----------------------
 www/secretary/workbench/views/actions/drop.json.rb |  4 +++-
 3 files changed, 9 insertions(+), 35 deletions(-)

diff --git a/www/secretary/workbench/models/attachment.rb b/www/secretary/workbench/models/attachment.rb
index 17738c3..030ff98 100644
--- a/www/secretary/workbench/models/attachment.rb
+++ b/www/secretary/workbench/models/attachment.rb
@@ -54,8 +54,8 @@ class Attachment
   # 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) # SafeTempFile forces encoding: BINARY
+    file = TempFile.new([safe_name, '.pdf'], encoding: Encoding::BINARY)
+    file.write(body)
     file.rewind
     file
   end
@@ -64,14 +64,14 @@ class Attachment
     ext = File.extname(name).downcase
     ext = '.pdf' if content_type.end_with? '/pdf'
 
-    file = SafeTempFile.new([safe_name, ext])
-    file.write(body) # SafeTempFile forces encoding: BINARY
+    file = TempFile.new([safe_name, ext], encoding: Encoding::BINARY)
+    file.write(body)
     file.rewind
 
     return file if ext == '.pdf'
 
     if IMAGE_TYPES.include? ext or content_type.start_with? 'image/'
-      pdf = SafeTempFile.new([safe_name, '.pdf'])
+      pdf = TempFile.new([safe_name, '.pdf'], encoding: Encoding::BINARY)
       img2pdf = File.expand_path('../img2pdf', __dir__)
       _stdout, stderr, status = Open3.capture3 img2pdf, '--output', pdf.path,
         file.path
@@ -80,7 +80,7 @@ class Attachment
       # use imagemagick to remove the alpha channel and try again.
       unless status.exitstatus == 0
         if stderr.include? 'remove the alpha channel'
-          tmppng = SafeTempFile.new([safe_name, '.png'])
+          tmppng = TempFile.new([safe_name, '.png'], encoding: Encoding::BINARY)
           system 'convert', file.path, '-background', 'white', '-alpha',
             'remove', '-alpha', 'off', tmppng.path
 
diff --git a/www/secretary/workbench/models/safetemp.rb b/www/secretary/workbench/models/safetemp.rb
deleted file mode 100644
index b3bf582..0000000
--- a/www/secretary/workbench/models/safetemp.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Tempfile in Ruby 2.3.0 has the unfortunate behavior of returning
-# an unsafe path and even blowing up when unlink is called in a $SAFE
-# environment.  This avoids those two problems, while forwarding all all other
-# method calls.
-#
-
-require 'tempfile'
-
-class SafeTempFile
-  def initialize *args
-    args << {} unless args.last.instance_of? Hash
-    args.last[:encoding] = Encoding::BINARY
-    @tempfile = Tempfile.new *args
-  end
-
-  def path
-    @tempfile.path
-  end
-
-  def unlink
-    File.unlink path
-  end
-
-  def method_missing symbol, *args
-    @tempfile.send symbol, *args
-  end
-end
diff --git a/www/secretary/workbench/views/actions/drop.json.rb b/www/secretary/workbench/views/actions/drop.json.rb
index 329c56f..0bd9e15 100644
--- a/www/secretary/workbench/views/actions/drop.json.rb
+++ b/www/secretary/workbench/views/actions/drop.json.rb
@@ -8,7 +8,9 @@ begin
   source = message.find(@source).as_pdf
   target = message.find(@target).as_pdf
 
-  output = SafeTempFile.new('output') # N.B. this is created as binary
+  # binary encoding was used by the SafeTempFile class, now removed
+  # It may no longer be necessary, but it probably does no harm
+  output = TempFile.new('output', encoding: Encoding::BINARY)
 
   Kernel.system 'pdfunite', target.path, source.path, output.path