diff --git a/lib/pigeon.rb b/lib/pigeon.rb index 5c85cde..d2a973d 100644 --- a/lib/pigeon.rb +++ b/lib/pigeon.rb @@ -208,7 +208,12 @@ module Pigeon end def self.mkdir_p(path) - FileUtils.makedirs(path) unless Dir.exists?(path) + if Dir.exists?(path) + FileUtils.makedirs(path) + else + end + rescue => x + binding.pry end def self.write_to_disk(base_path, mhash, data) diff --git a/lib/pigeon/database.rb b/lib/pigeon/database.rb index 6f64830..31d2d12 100644 --- a/lib/pigeon/database.rb +++ b/lib/pigeon/database.rb @@ -110,8 +110,10 @@ module Pigeon .flatten .uniq .map do |mhash| - blob_path = File.join(file_path, Helpers.hash2file_path(mhash)) - Helpers.write_to_disk(blob_path, mhash, get_blob(mhash)) + hash2filepath = Helpers.hash2file_path(mhash) + blob_path = File.join(file_path, hash2filepath) + blob = get_blob(mhash) + Helpers.write_to_disk(blob_path, mhash, blob) if blob end # Render messages for all peers. diff --git a/pigeon.db b/pigeon.db deleted file mode 100644 index 639f1ba..0000000 Binary files a/pigeon.db and /dev/null differ diff --git a/spec/pigeon/bundle_spec.rb b/spec/pigeon/bundle_spec.rb index 5df706f..637b726 100644 --- a/spec/pigeon/bundle_spec.rb +++ b/spec/pigeon/bundle_spec.rb @@ -47,8 +47,8 @@ RSpec.describe Pigeon::Message do it "ingests a bundle's blobs" do db.reset_database - db.add_message(db.add_blob("a.gif"), { - db.add_blob("b.gif") => db.add_blob("c.gif"), + db.add_message(db.add_blob(File.read("a.gif")), { + db.add_blob(File.read("b.gif")) => db.add_blob(File.read("c.gif")), }) db.export_bundle("./spec/fixtures/has_blobs") STDERR.puts("The directory structure is not correct.")