diff --git a/Gemfile b/Gemfile index 98d81ca70..679e0a5b2 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ unless RUBY_PLATFORM =~ /w32/ gem 'iconv' end -gem 'zipruby', '~> 0.3.6' #performance +gem 'rubyzip' gem 'delayed_job_active_record'#, :group => :production gem 'daemons' gem 'grape', '~> 0.9.0' diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 80e7c1c06..a3bee3c95 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -1,10 +1,11 @@ +require 'zip' class ZipdownController < ApplicationController #查找项目(课程) before_filter :find_project_by_bid_id, :only => [:assort] #检查权限 #勿删 before_filter :authorize, :only => [:assort,:download_user_homework] SAVE_FOLDER = "#{Rails.root}/files" - OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip" + OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip" #统一下载功能 def download @@ -181,23 +182,19 @@ class ZipdownController < ApplicationController zipfile_name = "#{output_path}/#{rename_zipfile}" 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| - flag = true - index = 1 rename_file = File.basename(filename) rename_file = filename_to_real( File.basename(filename)) if is_attachment - begin - zipfile.add_file(rename_file, filename) - flag = false + zipfile.add(rename_file, filename) 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 end end 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 zipfile_name