From 104633e9a01010f09180ca626bfec3c0811cd6df Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Thu, 3 Oct 2013 15:31:21 +0200 Subject: [PATCH] #146 - unicode file names in zip archives fixed --- Gemfile | 9 ++++----- init.rb | 5 ++++- lib/dmsf_zip.rb | 37 ++++++++++++------------------------- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/Gemfile b/Gemfile index 596b3740..890899e6 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/init.rb b/init.rb index ee78b3ed..075a40f3 100644 --- a/init.rb +++ b/init.rb @@ -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| diff --git a/lib/dmsf_zip.rb b/lib/dmsf_zip.rb index fee69e17..2b0dcb3e 100644 --- a/lib/dmsf_zip.rb +++ b/lib/dmsf_zip.rb @@ -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) }