Skip to content

Commit c6e7cd4

Browse files
author
Kirk Wang
committed
🐛 Fix #importer_unzip_path logic
We discovered a bug with the previous updates to the `#importer_unzip_path` method where when the method is being called to create a path, it returns `nil` because the path does not exist and the whole reason why we are calling the method is to create the path. We add a `mkdir` argument to differentiate between when we're looking up the path vs wanting to create it.
1 parent 70d4b8c commit c6e7cd4

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

app/models/bulkrax/importer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ def import_metadata_format
237237
# end
238238

239239
# If the import data is zipped, unzip it to this path
240-
def importer_unzip_path
240+
def importer_unzip_path(mkdir: false)
241241
@importer_unzip_path ||= File.join(parser.base_path, "import_#{path_string}")
242-
return @importer_unzip_path if Dir.exist?(@importer_unzip_path)
242+
return @importer_unzip_path if Dir.exist?(@importer_unzip_path) || mkdir == true
243243

244244
# turns "tmp/imports/tenant/import_1_20250122035229_1" to "tmp/imports/tenant/import_1_20250122035229"
245245
base_importer_unzip_path = @importer_unzip_path.split('_')[0...-1].join('_')

app/parsers/bulkrax/application_parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,15 +432,15 @@ def unzip(file_to_unzip)
432432

433433
Zip::File.open(file_to_unzip) do |zip_file|
434434
zip_file.each do |entry|
435-
entry_path = File.join(importer_unzip_path, entry.name)
435+
entry_path = File.join(importer_unzip_path(mkdir: true), entry.name)
436436
FileUtils.mkdir_p(File.dirname(entry_path))
437437
zip_file.extract(entry, entry_path) unless File.exist?(entry_path)
438438
end
439439
end
440440
end
441441

442442
def untar(file_to_untar)
443-
Dir.mkdir(importer_unzip_path) unless File.directory?(importer_unzip_path)
443+
Dir.mkdir(importer_unzip_path(mkdir: true)) unless File.directory?(importer_unzip_path)
444444
command = "tar -xzf #{Shellwords.escape(file_to_untar)} -C #{Shellwords.escape(importer_unzip_path)}"
445445
result = system(command)
446446
raise "Failed to extract #{file_to_untar}" unless result

0 commit comments

Comments
 (0)