-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
Description
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)})"