Added check if binary was written correctly.

This commit is contained in:
Martin Edenhofer 2016-02-07 16:36:10 +01:00
parent ea640474a3
commit 372e185dc0

View file

@ -11,9 +11,13 @@ add new file to store
store_file_id = Store::File.add(binary_data) store_file_id = Store::File.add(binary_data)
do also verify of written data
store_file_id = Store::File.add(binary_data, true)
=end =end
def self.add(data) def self.add(data, verify = true)
sha = Digest::SHA256.hexdigest(data) sha = Digest::SHA256.hexdigest(data)
file = Store::File.find_by(sha: sha) file = Store::File.find_by(sha: sha)
@ -30,6 +34,15 @@ add new file to store
provider: adapter_name, provider: adapter_name,
sha: sha, sha: sha,
) )
# verify
if verify
read_data = adapter.get(sha)
read_sha = Digest::SHA256.hexdigest(read_data)
if sha != read_sha
fail "Content not written correctly (provider #{adapter_name})."
end
end
end end
file file
end end