diff --git a/app/models/bulkrax/importer.rb b/app/models/bulkrax/importer.rb index 3e5d01967..166f375e1 100644 --- a/app/models/bulkrax/importer.rb +++ b/app/models/bulkrax/importer.rb @@ -239,6 +239,14 @@ def import_metadata_format # If the import data is zipped, unzip it to this path def importer_unzip_path @importer_unzip_path ||= File.join(parser.base_path, "import_#{path_string}") + return @importer_unzip_path if Dir.exist?(@importer_unzip_path) + + # 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('_') + + # If we don't have an existing unzip path, we'll try and find it. + # Just in case there are multiple paths, we sort by the number at the end of the path and get the last one + @importer_unzip_path = Dir.glob(base_importer_unzip_path + '*').sort_by { |path| path.split(base_importer_unzip_path).last[1..-1].to_i }.last end def errored_entries_csv_path diff --git a/app/parsers/bulkrax/csv_parser.rb b/app/parsers/bulkrax/csv_parser.rb index e1a7c2fba..bd7dc41a8 100644 --- a/app/parsers/bulkrax/csv_parser.rb +++ b/app/parsers/bulkrax/csv_parser.rb @@ -360,6 +360,10 @@ def path_to_files(**args) @path_to_files = File.join( zip? ? importer_unzip_path : File.dirname(import_file_path), 'files', filename ) + + return @path_to_files if File.exist?(@path_to_files) + + File.join(importer_unzip_path, 'files', filename) if file? && zip? end private diff --git a/spec/fixtures/csv/files/moon.jpg b/spec/fixtures/csv/files/moon.jpg new file mode 100644 index 000000000..136fed4c8 Binary files /dev/null and b/spec/fixtures/csv/files/moon.jpg differ