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 a911f883 Set mimetype for some file types
a911f883 is described below

commit a911f8838eb8409f3b63d37bc1dfeb5e49bd6683
Author: Sebb <[email protected]>
AuthorDate: Fri Apr 21 22:26:59 2023 +0100

    Set mimetype for some file types
---
 lib/whimsy/asf/svn.rb | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index 2c3da87c..0529dd66 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -778,7 +778,17 @@ module ASF
       throw IOError.new("Could not check if #{path} exists: #{err}")
     end
 
+    # Should agree with modules/whimsy_server/files/subversion-config-www in 
Puppet
+    MIMETYPES = { # if the extension matches, then apply the mime-type as below
+      '.jpg' => 'image/jpeg',
+      '.pdf' => 'application/pdf',
+      '.png' => 'image/png',
+      '.tif' => 'image/tiff',
+      '.tiff' => 'image/tiff',
+    }
+
     # create a new file and fail if it already exists
+    # sets the mimetype if the extension is present in the MIMETYPES hash
     # Parameters:
     #  directory - parent directory as an SVN URL
     #  filename - name of file to create
@@ -809,6 +819,11 @@ module ASF
           File.write(source, data, encoding: Encoding::BINARY)
         end
         commands = [['put', source.path, target]]
+        # Add mimetype if known
+        mimetype = MIMETYPES[File.extname(filename)]
+        if mimetype
+          commands << ['propset', 'svn:mime-type', mimetype, target]
+        end
         # Detect file created in parallel. This generates the error message:
         # svnmucc: E160020: File already exists: <snip> path 'xxx'
         rc = self.svnmucc_(commands, msg, env, _, parentrev, 
options.merge({tmpdir: tmpdir}))

Reply via email to