diff --git a/app/models/bulkrax/importer.rb b/app/models/bulkrax/importer.rb index 166f375e..be492514 100644 --- a/app/models/bulkrax/importer.rb +++ b/app/models/bulkrax/importer.rb @@ -237,9 +237,9 @@ def import_metadata_format # end # If the import data is zipped, unzip it to this path - def importer_unzip_path + def importer_unzip_path(mkdir: false) @importer_unzip_path ||= File.join(parser.base_path, "import_#{path_string}") - return @importer_unzip_path if Dir.exist?(@importer_unzip_path) + return @importer_unzip_path if Dir.exist?(@importer_unzip_path) || mkdir == true # turns "tmp/imports/tenant/import_1_20250122035229_1" to "tmp/imports/tenant/import_1_20250122035229" base_importer_unzip_path = @importer_unzip_path.split('_')[0...-1].join('_') diff --git a/app/parsers/bulkrax/application_parser.rb b/app/parsers/bulkrax/application_parser.rb index 161a6740..8e27b2d0 100644 --- a/app/parsers/bulkrax/application_parser.rb +++ b/app/parsers/bulkrax/application_parser.rb @@ -432,7 +432,7 @@ def unzip(file_to_unzip) Zip::File.open(file_to_unzip) do |zip_file| zip_file.each do |entry| - entry_path = File.join(importer_unzip_path, entry.name) + entry_path = File.join(importer_unzip_path(mkdir: true), entry.name) FileUtils.mkdir_p(File.dirname(entry_path)) zip_file.extract(entry, entry_path) unless File.exist?(entry_path) end @@ -440,7 +440,7 @@ def unzip(file_to_unzip) end def untar(file_to_untar) - Dir.mkdir(importer_unzip_path) unless File.directory?(importer_unzip_path) + Dir.mkdir(importer_unzip_path(mkdir: true)) unless File.directory?(importer_unzip_path) command = "tar -xzf #{Shellwords.escape(file_to_untar)} -C #{Shellwords.escape(importer_unzip_path)}" result = system(command) raise "Failed to extract #{file_to_untar}" unless result