Ignore faulty ZIP files
This commit is contained in:
@@ -2,7 +2,7 @@ class Account::DataImportJob < ApplicationJob
|
||||
include ActiveJob::Continuable
|
||||
|
||||
queue_as :backend
|
||||
discard_on Account::DataTransfer::RecordSet::IntegrityError
|
||||
discard_on Account::DataTransfer::RecordSet::IntegrityError, ZipFile::InvalidFileError
|
||||
|
||||
def perform(import)
|
||||
step :check do |step|
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
class ZipFile
|
||||
class InvalidFileError < StandardError; end
|
||||
|
||||
class << self
|
||||
def create_for(attachment, filename:)
|
||||
raise ArgumentError, "No block given" unless block_given?
|
||||
@@ -57,6 +59,12 @@ class ZipFile
|
||||
|
||||
blob.update!(byte_size: writer.byte_size, checksum: writer.checksum)
|
||||
attachment.attach(blob)
|
||||
rescue Aws::S3::MultipartUploadError => e
|
||||
if e.errors.any?
|
||||
raise e.errors.first
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
def create_for_disk(attachment, filename:)
|
||||
|
||||
@@ -2,6 +2,8 @@ class ZipFile::Reader
|
||||
def initialize(io)
|
||||
@io = io
|
||||
@reader = ZipKit::FileReader.read_zip_structure(io: io)
|
||||
rescue ZipKit::FileReader::InvalidStructure => e
|
||||
raise ZipFile::InvalidFileError, e.message
|
||||
end
|
||||
|
||||
def read(file_path)
|
||||
|
||||
Reference in New Issue
Block a user