Skip to content

Commit dc14a58

Browse files
chore(deps): bump rubyzip from 2.4.1 to 3.2.2
1 parent a362dcd commit dc14a58

7 files changed

Lines changed: 32 additions & 46 deletions

File tree

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ gem 'filename'
199199
# Required by CarrierWave, for image resizing
200200
gem 'mini_magick'
201201
# Library for reading and writing zip files
202-
gem 'rubyzip', require: 'zip'
202+
gem 'rubyzip', '~> 3.0', require: 'zip'
203203
# Manipulating XML files, needed for programming evaluation test report parsing.
204204
gem 'nokogiri', '>= 1.18.8'
205205

Gemfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ GEM
216216
docker-api (2.4.0)
217217
excon (>= 0.64.0)
218218
multi_json
219-
docx (0.9.1)
219+
docx (0.10.0)
220220
nokogiri (~> 1.13, >= 1.13.0)
221-
rubyzip (~> 2.0)
221+
rubyzip (>= 2.0, < 4)
222222
domain_name (0.6.20240107)
223223
dotenv (3.1.7)
224224
dotenv-rails (3.1.7)
@@ -608,16 +608,16 @@ GEM
608608
ruby-vips (2.2.2)
609609
ffi (~> 1.12)
610610
logger
611-
rubyzip (2.4.1)
611+
rubyzip (3.2.2)
612612
sanitize (7.0.0)
613613
crass (~> 1.0.2)
614614
nokogiri (>= 1.16.8)
615615
securerandom (0.4.1)
616-
selenium-webdriver (4.22.0)
616+
selenium-webdriver (4.43.0)
617617
base64 (~> 0.2)
618618
logger (~> 1.4)
619619
rexml (~> 3.2, >= 3.2.5)
620-
rubyzip (>= 1.2.2, < 3.0)
620+
rubyzip (>= 1.2.2, < 4.0)
621621
websocket (~> 1.0)
622622
should_not (1.1.0)
623623
shoulda-matchers (7.0.1)
@@ -779,7 +779,7 @@ DEPENDENCIES
779779
rubocop-rails
780780
ruby-oembed
781781
ruby-openai
782-
rubyzip
782+
rubyzip (~> 3.0)
783783
rwordnet!
784784
sanitize (>= 4.6.3)
785785
settings_on_rails!

app/services/course/assessment/submission/base_zip_download_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def zip_file_path
4242
#
4343
# @return [String] The path to the zip file.
4444
def zip_base_dir
45-
Zip::File.open(zip_file_path, Zip::File::CREATE) do |zip_file|
45+
Zip::File.open(zip_file_path, create: true) do |zip_file|
4646
Dir["#{@base_dir}/**/**"].each do |file|
4747
zip_file.add(file.sub(File.join("#{@base_dir}/"), ''), file)
4848
end

app/services/course/assessment/submission/ssid_zip_download_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def zip_base_dir
137137
answer_partitions = partition_answers_by_size(answer_size_hash)
138138
@zip_files = answer_partitions.map.with_index do |partition, index|
139139
output_file = "#{@base_dir}_#{index}.zip"
140-
Zip::File.open(output_file, Zip::File::CREATE) do |zip_file|
140+
Zip::File.open(output_file, create: true) do |zip_file|
141141
partition.each do |answer_dir|
142142
Dir["#{answer_dir}/**/**"].each do |file|
143143
zip_file.add(file.sub(File.join("#{@base_dir}/"), ''), file)

app/services/course/material/zip_download_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def download_to_base_dir
3939
#
4040
# @return [String] The path to the zip file.
4141
def zip_base_dir
42-
Zip::File.open(zip_file_path, Zip::File::CREATE) do |zip_file|
42+
Zip::File.open(zip_file_path, create: true) do |zip_file|
4343
Dir["#{@base_dir}/**/**"].each do |file|
4444
zip_file.add(file.sub(File.join("#{@base_dir}/"), ''), file)
4545
end

lib/autoload/course/assessment/programming_package.rb

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,29 @@ class Course::Assessment::ProgrammingPackage
5050
#
5151
# @overload initialize(path)
5252
# @param [String|Pathname] path The path to the package on disk.
53-
# @overload initialize(stream)
54-
# @param [IO] stream The stream to the file.
55-
def initialize(path_or_stream)
56-
case path_or_stream
53+
# @overload initialize(file)
54+
# @param [File] file The file object.
55+
def initialize(path_or_file)
56+
case path_or_file
5757
when String, Pathname
58-
@path = path_or_stream
59-
when IO
60-
@stream = path_or_stream
58+
@path = path_or_file
59+
when File
60+
@file_stream_obj = path_or_file
6161
else
62-
raise ArgumentError, 'Invalid path or stream object'
62+
raise ArgumentError, 'Invalid path or File object'
6363
end
6464
end
6565

6666
# Gets the file path to the provided package.
6767
#
68-
# @return [String] The path to the file.
69-
# @return [nil] If the package is associated with a stream.
68+
# @return [String] The path to the file, or the underlying path of the File object.
7069
def path
7170
if @file
7271
@file.name
7372
elsif @path
7473
@path.to_s
75-
elsif @stream.is_a?(File)
76-
@stream.path
74+
elsif @file_stream_obj
75+
@file_stream_obj.path
7776
end
7877
end
7978

@@ -170,8 +169,8 @@ def unzip_file(destination)
170169
ensure_file_open!
171170
@file.each do |entry|
172171
entry_path = File.join(destination, entry.name)
173-
FileUtils.mkdir_p(File.dirname(entry_path))
174-
@file.extract(entry, entry_path) unless File.exist?(entry_path)
172+
FileUtils.mkdir_p(destination)
173+
@file.extract(entry, destination_directory: destination) unless File.exist?(entry_path)
175174
end
176175
end
177176

@@ -210,19 +209,14 @@ def test_reports
210209

211210
# Ensures that the zip file is open.
212211
#
213-
# When a stream is open, some atypical code is required because Rubyzip doesn't support streams
214-
# in its API too well -- the entries in memory and loaded from stream are different.
215-
#
216212
# @raise [IllegalStateError] when the zip file is not open and it cannot be opened.
217213
def ensure_file_open!
218214
return if @file
219215

220216
if @path
221217
@file = Zip::File.open(@path.to_s)
222-
elsif @stream
223-
@file = Zip::File.new(@stream&.path, true)
224-
@file.read_from_stream(@stream)
225-
@file.instance_variable_set(:@stored_entries, @file.instance_variable_get(:@entry_set).dup)
218+
elsif @file_stream_obj
219+
@file = Zip::File.open_buffer(@file_stream_obj)
226220
end
227221
raise IllegalStateError unless @file
228222
end

spec/libraries/course/assessment/programming_package_spec.rb

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111
'empty_programming_question_template.zip')
1212

1313
def temp_package_path
14-
temp_package_stream.tap(&:close).path
15-
end
16-
17-
def temp_package_stream
18-
package_path = Rails.application.config.x.temp_folder.join('spec/packages')
19-
FileUtils.mkdir_p(package_path) unless Dir.exist?(package_path)
20-
Tempfile.create('programming_package', package_path)
14+
package_dir = Rails.application.config.x.temp_folder.join('spec/packages')
15+
FileUtils.mkdir_p(package_dir) unless Dir.exist?(package_dir)
16+
package_dir.join("programming_package_#{SecureRandom.hex}").to_s
2117
end
2218

2319
def open_package(path)
@@ -34,14 +30,9 @@ def open_package(path)
3430
end
3531
end
3632

37-
context 'when a file stream is specified' do
38-
let(:package_stream) { temp_package_stream }
39-
subject { open_package(package_stream) }
40-
before do
41-
IO.copy_stream(self.class::PACKAGE_PATH, package_stream)
42-
package_stream.seek(0)
43-
end
44-
33+
context 'when a File object is specified' do
34+
let(:package_path) { File.new(self.class::PACKAGE_PATH, 'rb') }
35+
after { package_path.close }
4536
it 'opens the file' do
4637
expect(subject.submission_files).not_to be_empty
4738
end
@@ -65,6 +56,7 @@ def open_package(path)
6556

6657
context 'when a File is given' do
6758
let(:package_path) { File.new(self.class::PACKAGE_PATH, 'rb') }
59+
after { package_path.close }
6860
it 'returns the path to the File' do
6961
expect(subject.path).to eq(self.class::PACKAGE_PATH)
7062
end

0 commit comments

Comments
 (0)