Check if the file exists before adding it

ZipKit creates a placeholder record when add_file is called, this record is then filled with the content that's passxed to write. But if the blob's file doesn't exist then an error is rased and the placeholder is never filled. This results in a ZIP that has a place in its catalog for the blob, but no contant for it, which makes it invalid.
This commit is contained in:
Stanko K.R.
2026-02-03 15:01:10 +01:00
parent ffce51a42f
commit 1c1a73c57c
@@ -9,11 +9,11 @@ class Account::DataTransfer::BlobFileRecordSet < Account::DataTransfer::RecordSe
end
def export_record(blob)
zip.add_file("storage/#{blob.key}", compress: false) do |out|
blob.download { |chunk| out.write(chunk) }
if blob.service.exist?(blob.key)
zip.add_file("storage/#{blob.key}", compress: false) do |out|
blob.download { |chunk| out.write(chunk) }
end
end
rescue ActiveStorage::FileNotFoundError
# Skip blobs where the file is missing from storage
end
def files