diff --git a/lib/pigeon/database.rb b/lib/pigeon/database.rb index 368bff5..c071bf9 100644 --- a/lib/pigeon/database.rb +++ b/lib/pigeon/database.rb @@ -157,8 +157,14 @@ module Pigeon .map(&:collect_blobs) .flatten .uniq - .map do |x| - binding.pry if x.start_with?("&622PRNJ7") + .map do |mhash| + rel_path = Helpers.hash2file_path(mhash) + from = File.join([file_path] + rel_path) + to = File.join([PIGEON_BLOB_PATH] + rel_path) + if (File.file?(from) && !File.file?(to)) + data = File.read(from) + Helpers.write_to_disk(PIGEON_BLOB_PATH, mhash, data) + end end messages end diff --git a/spec/pigeon/bundle_spec.rb b/spec/pigeon/bundle_spec.rb index 687e3e9..96d51da 100644 --- a/spec/pigeon/bundle_spec.rb +++ b/spec/pigeon/bundle_spec.rb @@ -47,7 +47,6 @@ RSpec.describe Pigeon::Message do it "ingests a bundle's blobs" do puts "WARNING: This test deletes the blob dir! Fix ASAP" - puts "WARNING: This bundle contains blobs, but does not reference them." `rm -rf #{Pigeon::PIGEON_BLOB_PATH}` db.reset_database blobs = [ @@ -56,7 +55,7 @@ RSpec.describe Pigeon::Message do "&YPF11E5N9JFVB6KB1N1WDVVT9DXMCHE0XJWBZHT2CQ29S5SEPCSG.sha256", ] db.import_bundle("./spec/fixtures/has_blobs") - expect(db.all_messages.count).to eq(1) + expect(db.all_messages.count).to eq(3) blobs.map do |h| expect(db.have_blob?(h)).to be true expect(db.get_blob(h)).to be_kind_of(String)