MCPcopy Index your code
hub / github.com/scality/cloudserver / checkHashMatchMD5

Function checkHashMatchMD5

lib/api/apiUtils/object/storeObject.js:19–40  ·  view source on GitHub ↗

* Check that `hashedStream.completedHash` matches header `stream.contentMD5` * and delete old data or remove 'hashed' listeners, if applicable. * @param {object} stream - stream containing the data * @param {object} hashedStream - instance of MD5Sum * @param {object} dataRetrievalInfo - object c

(stream, hashedStream, dataRetrievalInfo, log, cb)

Source from the content-addressed store, hash-verified

17 * error, dataRetrievalInfo, and completedHash (if any)
18 */
19function checkHashMatchMD5(stream, hashedStream, dataRetrievalInfo, log, cb) {
20 const contentMD5 = stream.contentMD5;
21 const completedHash = hashedStream.completedHash;
22 if (contentMD5 && completedHash && contentMD5 !== completedHash) {
23 log.debug('contentMD5 and completedHash do not match, deleting data', {
24 method: 'storeObject::dataStore',
25 completedHash,
26 contentMD5,
27 });
28 const dataToDelete = [];
29 dataToDelete.push(dataRetrievalInfo);
30 return data.batchDelete(dataToDelete, null, null, log, err => {
31 if (err) {
32 // failure of batch delete is only logged, client gets the
33 // error code about the md mismatch
34 log.error('error deleting old data', { error: err });
35 }
36 return cb(errors.BadDigest);
37 });
38 }
39 return cb(null, dataRetrievalInfo, completedHash);
40}
41
42/**
43 * Stores object and responds back with key and storage type

Callers 1

dataStoreFunction · 0.70

Calls 2

debugMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected