Dont trust sender to disclose hashes (lol).
This commit is contained in:
parent
791f86445c
commit
ba30d22886
|
@ -153,18 +153,28 @@ module Pigeon
|
||||||
bundle = File.read(File.join(file_path, MESSAGE_FILE))
|
bundle = File.read(File.join(file_path, MESSAGE_FILE))
|
||||||
tokens = Pigeon::Lexer.tokenize(bundle)
|
tokens = Pigeon::Lexer.tokenize(bundle)
|
||||||
messages = Pigeon::Parser.parse(self, tokens)
|
messages = Pigeon::Parser.parse(self, tokens)
|
||||||
|
wanted = Set.new
|
||||||
messages
|
messages
|
||||||
.map(&:collect_blobs)
|
.map(&:collect_blobs)
|
||||||
.flatten
|
.flatten
|
||||||
.uniq
|
.uniq
|
||||||
.map do |mhash|
|
.map do |mhash|
|
||||||
rel_path = Helpers.hash2file_path(mhash)
|
binary = Pigeon::Helpers.b32_decode(mhash.gsub(BLOB_SIGIL, ""))
|
||||||
from = File.join([file_path] + rel_path)
|
puts "Add #{mhash}"
|
||||||
to = File.join([DEFAULT_BLOB_DIR] + rel_path)
|
wanted.add(binary)
|
||||||
if (File.file?(from) && !File.file?(to))
|
end
|
||||||
data = File.read(from)
|
all_files = Dir[File.join(file_path, "*.blb"), File.join(file_path, "*.BLB")]
|
||||||
Helpers.write_to_disk(DEFAULT_BLOB_DIR, mhash, data)
|
all_files.map do |path|
|
||||||
|
data = File.read(path)
|
||||||
|
raw_digest = Digest::SHA256.digest(data)
|
||||||
|
if wanted.member?(raw_digest)
|
||||||
|
mhash = BLOB_SIGIL + Helpers.b32_encode(raw_digest)
|
||||||
|
rel_path = Helpers.hash2file_path(mhash)
|
||||||
|
from = File.join([file_path] + rel_path)
|
||||||
|
to = File.join([DEFAULT_BLOB_DIR] + rel_path)
|
||||||
|
if !File.file?(to)
|
||||||
|
Helpers.write_to_disk(DEFAULT_BLOB_DIR, mhash, data)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
messages
|
messages
|
||||||
|
|
Loading…
Reference in New Issue