mavam / trac-hub

:bookmark: Converts trac tickets to github issues.
http://mavam.github.io/trac-hub
BSD 3-Clause "New" or "Revised" License
13 stars 18 forks source link

support hashed attachments #8

Open srl295 opened 8 years ago

srl295 commented 8 years ago

attachments are stored in hashed format in the trac data dir now. maybe make this a switch.

diff --git a/trac-hub b/trac-hub
index daece2b..657260a 100755
--- a/trac-hub
+++ b/trac-hub
@@ -9,6 +9,8 @@ require 'yaml'
 require 'set'
 require 'singleton'
 require 'uri'
+require 'digest/sha1'
+

 class GracefulQuit
   include Singleton
@@ -341,7 +343,19 @@ class Migrator
           when 'attachment'
             text = "**Attachment added:**"
             if @attachurl
-              url="#{@attachurl}/#{i}/#{ticket[:filename]}"
+              #hashed URLs.   
+              #ticket 14/blahblah.java is in 
+              #  `fa3/fa35e192121eabf3dabf9f5ea6abdbcbc107ac3b/d8be6619342d0340df06a23e8a9f2b720ac32bc8.java`
+              #  <first 3 of # hash>/<full # hash>/<filename hash>.<extension>
+              hash_dir = Digest::SHA1.hexdigest("#{i}")  # 14 -> fa35e192121eabf3dabf9f5ea6abdbcbc107ac3b
+              hash_par = hash_dir[0,3] # 14 -> fa3
+              hash_file = Digest::SHA1.hexdigest("#{ticket[:filename]}") # -> d8be6619342d0340df06a23e8a9f2b720ac32bc8
+              file_suff = File.extname(ticket[:filename])
+              url="#{@attachurl}/#{hash_par}/#{hash_dir}/#{hash_file}#{file_suff}"
+
+              # OTHER WAY (non hashed)
+              #url="#{@attachurl}/#{i}/#{ticket[:filename]}"
+
               if [".png", ".jpg", ".gif", ".PNG", ".JPG", ".GIF"].include? File.extname(ticket[:filename])
                 text = "#{text} `#{ticket[:filename]}` (#{(ticket[:size]/1024.0).round(1)} KiB)\n![#{ticket[:filename]}](#{URI.escape(url)})"
mavam commented 8 years ago

In general, this looks good to me. Have you tested this successfully? I'm happy to merge a PR with this patch if you greenlight it.

srl295 commented 8 years ago

Yes, for an import of about a thousand issues. Worked great, may be behind some sort of switch.

Enviado desde nuestro iPhone.

El ago 29, 2016, a las 10:44 AM, Matthias Vallentin notifications@github.com escribió:

In general, this looks good to me. Have you tested this successfully? I'm happy to merge PR with this patch if you greenlight it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.