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 afd6e26 Simplify: write atts to provided path afd6e26 is described below commit afd6e26232ece21efae3b8cee85ba98e8f7766b2 Author: Sebb <s...@apache.org> AuthorDate: Thu Jul 23 23:03:31 2020 +0100 Simplify: write atts to provided path --- www/secretary/workbench/models/message.rb | 25 ++++++++++--------------- www/secretary/workbench/tasks.rb | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/www/secretary/workbench/models/message.rb b/www/secretary/workbench/models/message.rb index eccf9d6..b2ccc30 100644 --- a/www/secretary/workbench/models/message.rb +++ b/www/secretary/workbench/models/message.rb @@ -203,27 +203,22 @@ class Message # # write one or more attachments - # 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, content-type]] - def write_att(*attachments) + # returns list as follows: + # [[name, temp file name, content-type]] + def write_att(tmpdir, *attachments) files = [] # drop all nil and empty values attachments = attachments.flatten.reject {|name| name.to_s.empty?} - if attachments.flatten.length == 1 - attachment = attachments.first - att = find(attachment) - files << [attachment, att.as_file, att.content_type.untaint] - else - # write out selected attachment - attachments.each do |attachment, basename| - att = find(attachment) - files << [attachment, att.as_file, att.content_type.untaint] - end + # write out any remaining attachments + attachments.each do |name| + att = find(name) + path = File.join(tmpdir, name) + att.write_path(path) + files << [name, path, att.content_type.untaint] end + files end diff --git a/www/secretary/workbench/tasks.rb b/www/secretary/workbench/tasks.rb index a53bfdb..90ab4ef 100644 --- a/www/secretary/workbench/tasks.rb +++ b/www/secretary/workbench/tasks.rb @@ -80,7 +80,7 @@ class Wunderbar::JsonBuilder # Commit new file(s) and update associated index # e.g. add ccla.pdf, ccla.pdf.asc to documents/cclas/xyz/ and update officers/cclas.txt # Parameters: - # index_dir - SVN alias of directory containint the index (e.g. foundation or officers) + # index_dir - SVN alias of directory containing the index (e.g. foundation or officers) # index_name - name of index file to update (e.g. cclas.txt) # docdir - SVN alias for document directory (e.g. cclas) # docname - document name (as per email) @@ -91,11 +91,15 @@ class Wunderbar::JsonBuilder # svnmessage - the svn commit message # block - the block which is passed the contents of the index file to be updated def svn_multi(index_dir, index_name, docdir, docname, docsig, outfilename, outfileext, emessage, svnmessage, &block) - ASF::SVN.multiUpdate_(ASF::SVN.svnpath!(index_dir, index_name), svnmessage, env, _) do |text| + rc = nil + Dir.mktmpdir do |tmpdir| + + rc = ASF::SVN.multiUpdate_(ASF::SVN.svnpath!(index_dir, index_name), svnmessage, env, _,{tmpdir: tmpdir}) do |text| extras = [] # write the attachments as file(s) - dest = emessage.write_att(docname, docsig) + dest = emessage.write_att(tmpdir, docname, docsig) + Wunderbar.warn dest.inspect if dest.size > 1 # write to a container directory unless outfilename =~ /\A[a-zA-Z][-.\w]+\z/ # previously done by write_svn @@ -115,7 +119,7 @@ class Wunderbar::JsonBuilder end outpath = File.join(container, name) # N.B. file cannot exist here, because the directory was created as part of the same commit - extras << ['put', file.path, outpath] + extras << ['put', file, outpath] extras << ['propset', 'svn:mime-type', content_type, outpath] end else @@ -125,7 +129,7 @@ class Wunderbar::JsonBuilder if ASF::SVN.exist?(outpath, nil, env) raise IOError.new("#{outpath} already exists!") else - extras << ['put', file.path, outpath] + extras << ['put', file, outpath] extras << ['propset', 'svn:mime-type', content_type, outpath] end end @@ -134,6 +138,9 @@ class Wunderbar::JsonBuilder [text, extras] end + + end + rc end def template(name)