#146 - unicode file names in zip archives fixed

This commit is contained in:
Karel Picman 2013-10-03 15:31:21 +02:00
parent a899d85ca4
commit 104633e9a0
3 changed files with 20 additions and 31 deletions

View File

@ -1,11 +1,10 @@
source :rubygems
gem "rubyzip"
gem "simple_enum"
gem "nokogiri", ">= 1.4.2"
gem "uuidtools", "~> 2.1.1"
gem 'rubyzip', '>= 1.0.0'
gem 'simple_enum'
gem 'uuidtools', '~> 2.1.1'
#Allows --without=xapian
group :xapian do
gem "xapian-full", :require => false
gem 'xapian-full', :require => false
end

View File

@ -19,6 +19,7 @@
require 'redmine'
require 'redmine_dmsf'
require 'zip'
Redmine::Plugin.register :redmine_dmsf do
name "DMSF"
@ -126,8 +127,10 @@ Redmine::Plugin.register :redmine_dmsf do
end
nil
end
end
end
# Rubyzip configuration
Zip.unicode_names = true
end
Redmine::Search.map do |search|

View File

@ -16,43 +16,35 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'zip/zip'
require 'zip/zipfilesystem'
require 'iconv'
require 'zip'
class DmsfZip
attr_reader :files
def initialize()
@zip = Tempfile.new(["dmsf_zip",".zip"])
@zip = Tempfile.new(['dmsf_zip','.zip'])
@zip.chmod(0644)
@zip_file = Zip::ZipOutputStream.new(@zip.path)
@zip_file = Zip::OutputStream.new(@zip.path)
@files = []
end
def finish
@zip_file.close unless @zip_file.nil?
@zip.path unless @zip.nil?
@zip_file.close if @zip_file
@zip.path if @zip
end
def close
@zip_file.close unless @zip_file.nil?
@zip.close unless @zip.nil?
@zip_file.close if @zip_file
@zip.close if @zip
end
def add_file(file, root_path = nil)
string_path = file.folder.nil? ? "" : file.folder.dmsf_path_str + "/"
string_path = file.folder.nil? ? '' : "#{file.folder.dmsf_path_str}/"
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
string_path += file.name
#TODO: somewhat ugly conversion problems handling bellow
begin
string_path = Iconv.conv(Setting.plugin_redmine_dmsf["dmsf_zip_encoding"], "utf-8", string_path)
rescue
end
string_path += file.name
@zip_file.put_next_entry(string_path)
File.open(file.last_revision.disk_file, "rb") do |f|
buffer = ""
File.open(file.last_revision.disk_file, 'rb') do |f|
while (buffer = f.read(8192))
@zip_file.write(buffer)
end
@ -61,13 +53,8 @@ class DmsfZip
end
def add_folder(folder, root_path = nil)
string_path = folder.dmsf_path_str + "/"
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
#TODO: somewhat ugly conversion problems handling bellow
begin
string_path = Iconv.conv(Setting.plugin_redmine_dmsf["dmsf_zip_encoding"], "utf-8", string_path)
rescue
end
string_path = "#{folder.dmsf_path_str}/"
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
@zip_file.put_next_entry(string_path)
folder.subfolders.visible.each { |subfolder| self.add_folder(subfolder, root_path) }
folder.files.visible.each { |file| self.add_file(file, root_path) }