用回rubyzip, zipruby有bug.

This commit is contained in:
guange 2015-04-03 11:29:37 +08:00
parent 56df5ce9a7
commit 893f6af856
2 changed files with 7 additions and 10 deletions

View File

@ -6,7 +6,7 @@ unless RUBY_PLATFORM =~ /w32/
gem 'iconv' gem 'iconv'
end end
gem 'zipruby', '~> 0.3.6' #performance gem 'rubyzip'
gem 'delayed_job_active_record'#, :group => :production gem 'delayed_job_active_record'#, :group => :production
gem 'daemons' gem 'daemons'
gem 'grape', '~> 0.9.0' gem 'grape', '~> 0.9.0'

View File

@ -1,10 +1,11 @@
require 'zip'
class ZipdownController < ApplicationController class ZipdownController < ApplicationController
#查找项目(课程) #查找项目(课程)
before_filter :find_project_by_bid_id, :only => [:assort] before_filter :find_project_by_bid_id, :only => [:assort]
#检查权限 #检查权限
#勿删 before_filter :authorize, :only => [:assort,:download_user_homework] #勿删 before_filter :authorize, :only => [:assort,:download_user_homework]
SAVE_FOLDER = "#{Rails.root}/files" SAVE_FOLDER = "#{Rails.root}/files"
OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip" OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip"
#统一下载功能 #统一下载功能
def download def download
@ -181,23 +182,19 @@ class ZipdownController < ApplicationController
zipfile_name = "#{output_path}/#{rename_zipfile}" zipfile_name = "#{output_path}/#{rename_zipfile}"
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name)) Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
Zip::Archive.open(zipfile_name, Zip::CREATE) do |zipfile| Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
files_paths.each do |filename| files_paths.each do |filename|
flag = true
index = 1
rename_file = File.basename(filename) rename_file = File.basename(filename)
rename_file = filename_to_real( File.basename(filename)) if is_attachment rename_file = filename_to_real( File.basename(filename)) if is_attachment
begin begin
zipfile.add_file(rename_file, filename) zipfile.add(rename_file, filename)
flag = false
rescue Exception => e rescue Exception => e
zipfile.add_buffer('FILE_NOTICE.txt', l(:label_file_exist)) zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write l(:label_file_exist)}
next next
end end
end end
unless not_exist_file.empty? unless not_exist_file.empty?
zipfile.add_buffer('FILE_LOST.txt', l(:label_file_lost) + not_exist_file.join(',').to_s) zipfile.get_output_stream('FILE_LOST.txt'){|os| os.write l(:label_file_lost) + not_exist_file.join(',').to_s}
end end
end end
zipfile_name zipfile_name