Simplify: write atts to provided path
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 @@
#
# 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 @@
# 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 @@
# 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 @@
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 @@
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 @@
[text, extras]
end
+
+ end
+ rc
end
def template(name)