Skip to content

Commit 675bbeb

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

7 files changed

Lines changed: 27 additions & 39 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: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ 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

@@ -72,8 +72,8 @@ def path
7272
@file.name
7373
elsif @path
7474
@path.to_s
75-
elsif @stream.is_a?(File)
76-
@stream.path
75+
elsif @file_stream_obj
76+
@file_stream_obj.path
7777
end
7878
end
7979

@@ -170,8 +170,8 @@ def unzip_file(destination)
170170
ensure_file_open!
171171
@file.each do |entry|
172172
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)
173+
FileUtils.mkdir_p(destination)
174+
@file.extract(entry, destination_directory: destination) unless File.exist?(entry_path)
175175
end
176176
end
177177

@@ -219,10 +219,8 @@ def ensure_file_open!
219219

220220
if @path
221221
@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)
222+
elsif @file_stream_obj
223+
@file = Zip::File.open_buffer(@file_stream_obj)
226224
end
227225
raise IllegalStateError unless @file
228226
end

spec/libraries/course/assessment/programming_package_spec.rb

Lines changed: 3 additions & 13 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
1814
package_path = Rails.application.config.x.temp_folder.join('spec/packages')
1915
FileUtils.mkdir_p(package_path) unless Dir.exist?(package_path)
20-
Tempfile.create('programming_package', package_path)
16+
Tempfile.create('programming_package', package_path).tap(&:close).path
2117
end
2218

2319
def open_package(path)
@@ -34,14 +30,8 @@ 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') }
4535
it 'opens the file' do
4636
expect(subject.submission_files).not_to be_empty
4737
end

0 commit comments

Comments
 (0)