Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support hashed attachments #8

Open
srl295 opened this issue Aug 25, 2016 · 2 comments
Open

support hashed attachments #8

srl295 opened this issue Aug 25, 2016 · 2 comments

Comments

@srl295
Copy link
Contributor

srl295 commented Aug 25, 2016

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
Copy link
Owner

mavam commented Aug 29, 2016

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
Copy link
Contributor Author

srl295 commented Aug 30, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants