diff --git a/app/parsers/bulkrax/csv_parser.rb b/app/parsers/bulkrax/csv_parser.rb index e1a7c2fba..d63059087 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(real_importer_unzip_path, 'files', filename) if file? && zip? end private @@ -379,7 +383,7 @@ def unique_collection_identifier(collection_hash) # We expect a single CSV at the top level of the zip in the CSVParser # but we are willing to go look for it if need be def real_import_file_path - return Dir["#{importer_unzip_path}/**/*.csv"].reject { |path| in_files_dir?(path) }.first if file? && zip? + return Dir["#{real_importer_unzip_path}/**/*.csv"].reject { |path| in_files_dir?(path) }.first if file? && zip? parser_fields['import_file_path'] end @@ -389,5 +393,18 @@ def real_import_file_path def in_files_dir?(path) File.dirname(path).ends_with?('files') end + + # 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 + def real_importer_unzip_path + return importer_unzip_path if Dir.exist?(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 base_importer_unzip_path + # turns "tmp/imports/tenant/import_1_20250122035229_1" to "tmp/imports/tenant/import_1_20250122035229" + importer_unzip_path.split('_')[0...-1].join('_') + end end end diff --git a/app/views/bulkrax/importers/_edit_item_buttons.html.erb b/app/views/bulkrax/importers/_edit_item_buttons.html.erb index 4a7987abc..3c16bd393 100644 --- a/app/views/bulkrax/importers/_edit_item_buttons.html.erb +++ b/app/views/bulkrax/importers/_edit_item_buttons.html.erb @@ -5,6 +5,7 @@
Options for Updating an Entry

Rebuild metadata and files.

+

Files may be duplicated if this option is used on a successful entry. Consider using Remove and then Build instead.

<%= link_to 'Build', item_entry_path(item, e), method: :patch, class: 'btn btn-primary' %>

Remove existing work and then recreate the works metadata and files.

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