Skip to content

Commit

Permalink
🐛 Fix rerun for entries that came from zips (#1013)
Browse files Browse the repository at this point in the history
Previously, when rerunning an entry that came from a zip file, the rerun
would fail because it would look for the CSV in an assumed location
which is based on it's last importer ID.  Since this was a rerun, it
does not do an unzip into the assumed location so the directory does not
exist.

This commit will first check if the assumed location exists, and if not,
it will look for the location of the last unizpped files and use that
for the rerun.

Ref:
- notch8/palni_palci_knapsack#210
  • Loading branch information
kirkkwang authored Jan 29, 2025
1 parent 0e8de61 commit 70d4b8c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/bulkrax/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/parsers/bulkrax/csv_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added spec/fixtures/csv/files/moon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 70d4b8c

Please sign in to comment.