From 372e185dc0ba3b8ea8b928cf2e65434cbf3401e6 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 7 Feb 2016 16:36:10 +0100 Subject: [PATCH] Added check if binary was written correctly. --- app/models/store/file.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/store/file.rb b/app/models/store/file.rb index 6654e58b7..4004f703e 100644 --- a/app/models/store/file.rb +++ b/app/models/store/file.rb @@ -11,9 +11,13 @@ add new file to store store_file_id = Store::File.add(binary_data) +do also verify of written data + + store_file_id = Store::File.add(binary_data, true) + =end - def self.add(data) + def self.add(data, verify = true) sha = Digest::SHA256.hexdigest(data) file = Store::File.find_by(sha: sha) @@ -30,6 +34,15 @@ add new file to store provider: adapter_name, 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 file end