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 60f73e01 Allow for file input to be a Tempfile
60f73e01 is described below

commit 60f73e012ac48862f57da4816caaf13f74a1f8db
Author: Sebb <[email protected]>
AuthorDate: Tue Apr 18 00:21:04 2023 +0100

    Allow for file input to be a Tempfile
---
 lib/whimsy/asf/svn.rb | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index a74f8dc1..8ea17bd4 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -778,12 +778,11 @@ module ASF
       throw IOError.new("Could not check if #{path} exists: #{err}")
     end
 
-    # DRAFT DRAFT
     # create a new file and fail if it already exists
     # Parameters:
     #  directory - parent directory as an SVN URL
     #  filename - name of file to create
-    #  text - text of file to create
+    #  data - content of file: can be a text string, or a Tempfile
     #  msg - commit message
     #  env - user/pass
     #  _ - wunderbar context
@@ -794,7 +793,7 @@ module ASF
     # 0 on success
     # 1 if the file exists
     # IOError on unexpected error
-    def self.create_(directory, filename, text, msg, env, _, options={})
+    def self.create_(directory, filename, data, msg, env, _, options={})
       parentrev, err = self.getInfoItem(directory, 'revision', env.user, 
env.password)
       unless parentrev
         throw RuntimeError.new("Failed to get revision for #{directory}: 
#{err}")
@@ -803,8 +802,12 @@ module ASF
       return 1 if self.exist?(target, parentrev, env, options.reject {|k,v| k 
== :dryrun}) # need this to run!
       rc = nil
       Dir.mktmpdir do |tmpdir|
-        source = Tempfile.new('create_source', tmpdir)
-        File.write(source, text)
+        if data.instance_of? Tempfile
+          source = data
+        else
+          source = Tempfile.new('create_source', tmpdir)
+          File.write(source, data, encoding: Encoding::BINARY)
+        end
         commands = [['put', source.path, target]]
         # Detect file created in parallel. This generates the error message:
         # svnmucc: E160020: File already exists: <snip> path 'xxx'

Reply via email to