rubyzip 1.0.0 upgrade

test plan: zip functionality should continue to work, including:
 * course exports and imports
 * zip file uploads
 * zip submissions

also, the selenium dependency on rubyzip 1.0.0 is resolved
and we're making progress toward > 4GB exports

Change-Id: I58c5b0644b1e7fbb289821c9c0901f00750988de
Reviewed-on: https://gerrit.instructure.com/25474
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Bryan Madsen <bryan@instructure.com>
Product-Review: Bryan Madsen <bryan@instructure.com>
QA-Review: Matt Fairbourn <mfairbourn@instructure.com>
This commit is contained in:
Jeremy Stanley 2013-10-21 14:09:01 -06:00 committed by Bracken Mosbacker
parent b2fbc29447
commit 1e29a97ee0
26 changed files with 54 additions and 50 deletions

View File

@ -89,7 +89,8 @@ gem 'rscribd', '1.2.0'
gem 'net-ldap', '0.3.1', :require => 'net/ldap'
gem 'ruby-saml-mod', '0.1.22'
gem 'rubycas-client', '2.2.1'
gem 'rubyzip', '0.9.5', :require => 'zip/zip'
gem 'rubyzip', '1.0.0', :require => 'zip'
gem 'zip-zip', '0.2' # needed until plugins use the new namespace
gem 'safe_yaml-instructure', '0.8.0', :require => false
gem 'sanitize', '2.0.3'
gem 'shackles', '1.0.1'
@ -140,7 +141,7 @@ group :test do
gem 'rspec', '2.13.0'
gem 'rspec-rails', '2.13.0'
end
gem 'selenium-webdriver', '2.35.0'
gem 'selenium-webdriver', '2.37.0'
gem 'webrat', '0.7.3'
gem 'yard', '0.8.0'
gem 'yard-appendix', '>=0.1.8'

View File

@ -376,7 +376,7 @@ class ContentMigration < ActiveRecord::Base
begin
@exported_data_zip = download_exported_data
@zip_file = Zip::ZipFile.open(@exported_data_zip.path)
@zip_file = Zip::File.open(@exported_data_zip.path)
@exported_data_zip.close
data = JSON.parse(@zip_file.read('course_export.json'), :max_nesting => 50)
data = prepare_data(data)

View File

@ -3,9 +3,9 @@
# Tag the string as UTF-8 if it's valid UTF-8 so we can search
# for files with non-ASCII names inside archives.
require 'zip/zip'
require 'zip'
Zip::ZipEntry::class_eval do
Zip::Entry::class_eval do
def fix_name_encoding
@name.force_encoding('UTF-8')
@name.force_encoding('ASCII-8BIT') unless @name.valid_encoding?

View File

@ -16,7 +16,7 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require 'zip/zip'
require 'zip'
module Canvas::AccountReports
REPORTS = {}
@ -70,7 +70,7 @@ module Canvas::AccountReports
filepath = temp.path
temp.close!
Zip::ZipFile.open(filepath, Zip::ZipFile::CREATE) do |zipfile|
Zip::File.open(filepath, Zip::File::CREATE) do |zipfile|
csv.each do |report_name, contents|
zipfile.add(report_name + ".csv", contents)
end

View File

@ -1,7 +1,7 @@
require 'json'
require 'time'
require 'set'
require 'zip/zip'
require 'zip'
require 'net/http'
require 'uri'
require 'cgi'

View File

@ -102,7 +102,7 @@ class Migrator
zip_file = File.join(@base_export_dir, MigratorHelper::ALL_FILES_ZIP)
make_export_dir
Zip::ZipFile.open(zip_file, 'w') do |zipfile|
Zip::File.open(zip_file, 'w') do |zipfile|
@course[:file_map].each_value do |val|
file_path = File.join(base_dir, val[:real_path] || val[:path_name])
val.delete :real_path

View File

@ -17,7 +17,7 @@ module Canvas::Migration
end
def identify_package
zip_file = Zip::ZipFile.open(@archive.path)
zip_file = Zip::File.open(@archive.path)
if zip_file.find_entry("AngelManifest.xml")
:angel_7_4
elsif zip_file.find_entry("angelData.xml")

View File

@ -46,7 +46,7 @@ module Canvas::Migration::Worker
att = nil
begin
Zip::ZipFile.open(zip_file, 'w') do |zipfile|
Zip::File.open(zip_file, 'w') do |zipfile|
Dir["#{folder}/**/**"].each do |file|
next if File.basename(file) == file_name
file_path = file.sub(folder+'/', '')

View File

@ -18,7 +18,7 @@
require 'builder'
require 'digest'
require 'set'
require 'zip/zip'
require 'zip'
# Canvas Common Cartridge
module CC

View File

@ -144,7 +144,7 @@ module CC
end
FileUtils::mkdir_p File.join(@export_dir, ZIP_DIR)
@zip_path = File.join(@export_dir, ZIP_DIR, @zip_name)
@zip_file = Zip::ZipFile.new(@zip_path, Zip::ZipFile::CREATE)
@zip_file = Zip::File.new(@zip_path, Zip::File::CREATE)
end
end

View File

@ -69,7 +69,7 @@ module CC::Importer::Canvas
zip_file = File.join(@base_export_dir, 'all_files.zip')
make_export_dir
path = get_full_path(WEB_RESOURCES_FOLDER)
Zip::ZipFile.open(zip_file, 'w') do |zipfile|
Zip::File.open(zip_file, 'w') do |zipfile|
Dir["#{path}/**/**"].each do |file|
file_path = file.sub(path+'/', '')
zipfile.add(file_path, file)

View File

@ -56,7 +56,7 @@ module CC::Importer::Standard
zip_file = File.join(@base_export_dir, 'all_files.zip')
make_export_dir
Zip::ZipFile.open(zip_file, 'w') do |zipfile|
Zip::File.open(zip_file, 'w') do |zipfile|
file_map.each_value do |val|
file_path = File.join(@unzipped_file_path, val[:path_name])
if File.exists?(file_path)

View File

@ -15,11 +15,12 @@
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require 'zip/zip'
require 'zip'
require 'action_controller_test_process'
require 'tmpdir'
require 'set'
class ContentZipper
def initialize(options={})
@ -78,7 +79,7 @@ class ContentZipper
make_zip_tmpdir(filename) do |zip_name|
@logger.debug("creating #{zip_name}")
Zip::ZipFile.open(zip_name, Zip::ZipFile::CREATE) do |zipfile|
Zip::File.open(zip_name, Zip::File::CREATE) do |zipfile|
count = submissions.length
submissions.each_with_index do |submission, idx|
@assignment = assignment
@ -183,7 +184,7 @@ class ContentZipper
make_zip_tmpdir(filename) do |zip_name|
idx = 0
count = static_attachments.length + 2
Zip::ZipFile.open(zip_name, Zip::ZipFile::CREATE) do |zipfile|
Zip::File.open(zip_name, Zip::File::CREATE) do |zipfile|
update_progress(zip_attachment, idx, count)
portfolio.eportfolio_entries.each do |entry|
filename = "#{entry.full_slug}.html"
@ -231,7 +232,7 @@ class ContentZipper
filename = "#{folder.context.short_name}-#{folder.name} files"
make_zip_tmpdir(filename) do |zip_name|
@logger.debug("creating #{zip_name}")
Zip::ZipFile.open(zip_name, Zip::ZipFile::CREATE) do |zipfile|
Zip::File.open(zip_name, Zip::File::CREATE) do |zipfile|
@logger.debug("zip_name: #{zip_name}")
process_folder(folder, zipfile)
end
@ -322,7 +323,7 @@ class ContentZipper
handle = nil
begin
handle = attachment.open(:need_local_file => true)
zipfile.get_output_stream(filename){|zos| IOExtras.copy_stream(zos, handle)}
zipfile.get_output_stream(filename){|zos| Zip::IOExtras.copy_stream(zos, handle)}
rescue => e
@logger.error(" skipping #{attachment.full_filename} with error: #{e.message}")
return false

View File

@ -16,7 +16,7 @@ class QuizSubmissionZipper < ContentZipper
mark_attachment_as_zipping!(zip_attachment)
make_zip_tmpdir(filename) do |zip_name|
@logger.debug("creating #{zip_name}")
Zip::ZipFile.open(zip_name, Zip::ZipFile::CREATE) do |zipfile|
Zip::File.open(zip_name, Zip::File::CREATE) do |zipfile|
count = attachments_with_filenames.size
attachments_with_filenames.each_with_index do |arr,idx|
attachment,filename = arr

View File

@ -16,7 +16,7 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require 'zip/zip'
require 'zip'
module SIS
module CSV
@ -314,7 +314,7 @@ module SIS
end
def unzip_file(file, dest)
Zip::ZipFile.open(file) do |zip_file|
Zip::File.open(file) do |zip_file|
zip_file.each do |f|
f_path = File.join(dest, f.name)
FileUtils.mkdir_p(File.dirname(f_path))

View File

@ -95,7 +95,7 @@ class UnzipAttachment
@attachments = []
id_positions = {}
path_positions = zip_stats.paths_with_positions(last_position)
Zip::ZipFile.open(self.filename).each_with_index do |entry, index|
Zip::File.open(self.filename).each_with_index do |entry, index|
next if should_skip?(entry)
folder_path_array = path_elements_for(@context_files_folder.full_name)
@ -280,7 +280,7 @@ class ZipFileStats
private
def process!
Zip::ZipFile.open(filename).each do |entry|
Zip::File.open(filename).each do |entry|
@file_count += 1
@total_size += [entry.size, Attachment.minimum_size_for_quota].max
@paths << entry.name

View File

@ -17,7 +17,7 @@
#
require 'rubygems'
require 'zip/zip'
require 'zip'
require 'fileutils'
# Call this with a block. The block will take an array of filenames
@ -39,7 +39,7 @@ class ZipExtractor
attr_reader :filename, :zip, :unzipped_files
def initialize(filename)
@filename = filename
@zip = Zip::ZipFile.open(@filename)
@zip = Zip::File.open(@filename)
end
# Grabs all files and dumps them into a temporary directory.

View File

@ -41,7 +41,7 @@ describe "Common Cartridge exporting" do
@ce.export_course_without_send_later
@ce.error_messages.should == []
@file_handle = @ce.attachment.open :need_local_file => true
@zip_file = Zip::ZipFile.open(@file_handle.path)
@zip_file = Zip::File.open(@file_handle.path)
@manifest_body = @zip_file.read("imsmanifest.xml")
@manifest_doc = Nokogiri::XML.parse(@manifest_body)
end

View File

@ -541,7 +541,7 @@ describe "non-ASCII attachment names" do
"web_resources/abc.txt"]
@converter.resources.values.map { |v| v[:files][0][:href] }.sort.should == contents.sort
Zip::ZipFile.open File.join(@converter.base_export_dir, "all_files.zip") do |zipfile|
Zip::File.open File.join(@converter.base_export_dir, "all_files.zip") do |zipfile|
zipcontents = zipfile.entries.map(&:name)
(contents - zipcontents).should eql []
end

View File

@ -37,8 +37,10 @@ describe ContentZipper do
/other-567--guy-8/,
/some-999----1234-guy/,
]
Zip::ZipFile.foreach(attachment.reload.full_filename).each { |f|
f.name.should =~ expected_file_patterns.shift
Zip::File.foreach(attachment.reload.full_filename) { |f|
expect {
expected_file_patterns.delete_if { |expected_pattern| f.name =~ expected_pattern }
}.to change { expected_file_patterns.size }.by(-1)
}
expected_file_patterns.should be_empty
end
@ -55,7 +57,7 @@ describe ContentZipper do
ContentZipper.process_attachment(attachment, @teacher)
attachment.reload
attachment.workflow_state.should == 'zipped'
Zip::ZipFile.foreach(attachment.full_filename) do |f|
Zip::File.foreach(attachment.full_filename) do |f|
if f.file?
f.name.should =~ /some-999----1234-guy/
f.get_input_stream.read.should match(%r{This submission was a url, we&#39;re taking you to the url link now.})
@ -75,7 +77,7 @@ describe ContentZipper do
ContentZipper.process_attachment(attachment, @teacher)
attachment.reload
attachment.workflow_state.should == 'zipped'
Zip::ZipFile.foreach(attachment.full_filename) do |f|
Zip::File.foreach(attachment.full_filename) do |f|
if f.file?
f.get_input_stream.read.should be_include("hai this is my answer")
end
@ -120,11 +122,11 @@ describe ContentZipper do
ContentZipper.process_attachment(attachment, @teacher)
sub_count = 0
expected_file_names = [/group-0/, /group-1/]
Zip::ZipFile.foreach(attachment.full_filename) do |f|
f.name.should =~ expected_file_names.shift
sub_count += 1
Zip::File.foreach(attachment.full_filename) do |f|
expect {
expected_file_names.delete_if { |expected_name| f.name =~ expected_name }
}.to change { expected_file_names.size }.by(-1)
end
sub_count.should == 2
end
end
@ -171,7 +173,7 @@ describe ContentZipper do
ContentZipper.process_attachment(@attachment, user, :check_user => check_user)
names = []
@attachment.reload
Zip::ZipFile.foreach(@attachment.full_filename) {|f| names << f.name if f.file? }
Zip::File.foreach(@attachment.full_filename) {|f| names << f.name if f.file? }
names.sort
end
@ -241,7 +243,7 @@ describe ContentZipper do
ContentZipper.process_attachment(attachment, @user)
attachment.reload
names = []
Zip::ZipFile.foreach(attachment.full_filename) {|f| names << f.name if f.file? }
Zip::File.foreach(attachment.full_filename) {|f| names << f.name if f.file? }
names.should == ['otherfile.png']
end
end
@ -266,7 +268,7 @@ describe ContentZipper do
attachment.context = eportfolio
attachment.save!
Dir.expects(:mktmpdir).once.yields('/tmp')
Zip::ZipFile.expects(:open).once.with('/tmp/etcpasswd.zip', Zip::ZipFile::CREATE)
Zip::File.expects(:open).once.with('/tmp/etcpasswd.zip', Zip::File::CREATE)
ContentZipper.process_attachment(attachment, user)
end
end

View File

@ -14,7 +14,7 @@ describe "rubyzip encoding fix patch" do
tmpzipfile = Tempfile.new('zipfile')
@zip_path = tmpzipfile.path
tmpzipfile.close!
Zip::ZipFile.open(@zip_path, true) do |arch|
Zip::File.open(@zip_path, true) do |arch|
arch.add @utf8_name, @tmpfile.path
arch.add @ascii_name, @tmpfile.path
end
@ -27,7 +27,7 @@ describe "rubyzip encoding fix patch" do
context "with zip file" do
before(:each) do
@arch = Zip::ZipFile.open(@zip_path, 'r')
@arch = Zip::File.open(@zip_path, 'r')
end
after(:each) do

View File

@ -97,7 +97,7 @@ describe QuizSubmissionZipper do
zip_attachment: attachment).zip!
attachment.reload
attachment.should be_zipped
names = Zip::ZipFile.foreach(attachment.full_filename).map { |f| f.name }
names = Zip::File.foreach(attachment.full_filename) { |f| f.name }
names.length.should == 1
names.first.should == "user#{student.id}_question_#{question.id}_#{attach.id}_#{attach.display_name}"
end

View File

@ -109,7 +109,7 @@ describe UnzipAttachment do
it "should import files alphabetically" do
filename = fixture_filename('alphabet_soup.zip')
Zip::ZipFile.open(filename) do |zip|
Zip::File.open(filename) do |zip|
# make sure the files aren't read from the zip in alphabetical order (so it's not alphabetized by chance)
fake_files = []
fake_files << zip.get_entry('f.txt')
@ -119,7 +119,7 @@ describe UnzipAttachment do
fake_files << zip.get_entry('b.txt')
fake_files << zip.get_entry('a.txt')
Zip::ZipFile.stubs(:open).returns(fake_files)
Zip::File.stubs(:open).returns(fake_files)
ua = UnzipAttachment.new(:course => @course, :filename => 'fake')
ua.process

View File

@ -31,7 +31,7 @@ describe SisBatch do
# it'll try to delete the file later during finalization, which is
# not a convenient time for us.
tempfile.close!
Zip::ZipFile.open(path, Zip::ZipFile::CREATE) do |z|
Zip::File.open(path, Zip::File::CREATE) do |z|
data.each do |dat|
z.get_output_stream("csv_#{i}.csv") { |f| f.puts(dat) }
i += 1

View File

@ -44,7 +44,7 @@ describe "content exports" do
@export.export_type.should == 'qti'
file_handle = @export.attachment.open :need_local_file => true
zip_file = Zip::ZipFile.open(file_handle.path)
zip_file = Zip::File.open(file_handle.path)
manifest_doc = Nokogiri::XML.parse(zip_file.read("imsmanifest.xml"))
manifest_doc.at_css("resource[identifier=#{CC::CCHelper.create_key(q1)}]").should_not be_nil

View File

@ -1,7 +1,7 @@
# encoding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../../../../spec/spec_helper')
require 'zip/zipfilesystem'
require 'zip/filesystem'
if Qti.migration_executable
@ -40,7 +40,7 @@ describe Qti::Converter do
it "should publish as assignment on import if specified" do
copy = Tempfile.new(['spec-canvas', '.zip'])
FileUtils.cp(fname, copy.path)
Zip::ZipFile.open(copy.path) do |zf|
Zip::File.open(copy.path) do |zf|
zf.file.open("settings.xml", 'w') do |f|
f.write <<-XML
<settings>
@ -65,7 +65,7 @@ describe Qti::Converter do
it "should re-use the same assignment on update" do
copy = Tempfile.new(['spec-canvas', '.zip'])
FileUtils.cp(fname, copy.path)
Zip::ZipFile.open(copy.path) do |zf|
Zip::File.open(copy.path) do |zf|
zf.file.open("settings.xml", 'w') do |f|
f.write <<-XML
<settings>