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 2020/07/21 22:14:40 UTC

[whimsy] branch master updated: Ensure temporary files are retained

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 ecf12b6  Ensure temporary files are retained
ecf12b6 is described below

commit ecf12b6ca4f16a69355a76b974da272473fb990d
Author: Sebb <se...@apache.org>
AuthorDate: Tue Jul 21 23:14:31 2020 +0100

    Ensure temporary files are retained
---
 www/secretary/workbench/models/attachment.rb |  3 +++
 www/secretary/workbench/models/message.rb    | 10 ++++++----
 www/secretary/workbench/tasks.rb             |  8 ++++----
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/www/secretary/workbench/models/attachment.rb b/www/secretary/workbench/models/attachment.rb
index afded69..9daf050 100644
--- a/www/secretary/workbench/models/attachment.rb
+++ b/www/secretary/workbench/models/attachment.rb
@@ -44,6 +44,9 @@ class Attachment
     name.untaint
   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)
diff --git a/www/secretary/workbench/models/message.rb b/www/secretary/workbench/models/message.rb
index 0ff58f8..49af9ed 100644
--- a/www/secretary/workbench/models/message.rb
+++ b/www/secretary/workbench/models/message.rb
@@ -203,8 +203,10 @@ class Message
 
   #
   # write one or more attachments
-  # returns list of temporary file names
-  # [[name, path]]
+  # returns list of input names with their temporary file pointers
+  # It's not safe to return the path names of the temp files as
+  # that allows the files to be deleted by garbage collection
+  # [[name, open temp file]]
   def write_att(*attachments)
     files = []
 
@@ -216,11 +218,11 @@ class Message
 
     if attachments.flatten.length == 1
       attachment = attachments.first
-      files << [attachment, find(attachment).as_file.path]
+      files << [attachment, find(attachment).as_file]
     else
       # write out selected attachment
       attachments.each do |attachment, basename|
-        files << [attachment, find(attachment).as_file.path]
+        files << [attachment, find(attachment).as_file]
       end
     end
     files
diff --git a/www/secretary/workbench/tasks.rb b/www/secretary/workbench/tasks.rb
index cba6bd1..209c45d 100644
--- a/www/secretary/workbench/tasks.rb
+++ b/www/secretary/workbench/tasks.rb
@@ -103,12 +103,12 @@ class Wunderbar::JsonBuilder
         end
         container = ASF::SVN.svnpath!(docdir, outfilename)
         extras << ['mkdir', container]
-        dest.each do |name, path|
-          extras << ['put', path, File.join(container, name)]
+        dest.each do |name, file|
+          extras << ['put', file.path, File.join(container, name)]
         end
       else
-        name, path = dest.flatten
-        extras << ['put', path, ASF::SVN.svnpath!(docdir,"#{outfilename}#{outfileext}")]
+        name, file = dest.flatten
+        extras << ['put', file.path, ASF::SVN.svnpath!(docdir,"#{outfilename}#{outfileext}")]
       end
 
       text = yield text # update the index