Skip to content

Commit 565600f

Browse files
invalidate hash if files does not have hash
1 parent 2892f27 commit 565600f

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

lib/models/mongo/infra-code-version.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var regexpQuote = require('regexp-quote');
1010
var bcrypt = require('bcrypt');
1111
var jsonHash = require('json-stable-stringify');
1212
var dogstatsd = require('models/datadog');
13+
var uuid = require('uuid');
1314

1415
var path = require('path');
1516
var join = path.join;
@@ -581,18 +582,26 @@ InfraCodeVersionSchema.methods.getHash = function (cb) {
581582
}, function (err, infraCodeVersion) {
582583
if (err) { return cb(err); }
583584
var hashMap = {};
585+
var invalidate = false;
584586
infraCodeVersion.files.forEach(function(item) {
585587
var filePath = item.Key.substr(item.Key.indexOf('/'));
586-
if (item.hash) {
587-
// remove context version from Key
588-
hashMap[filePath] = item.hash;
589-
} else { // item.isDir === true
588+
if (item.isDir) {
590589
// ensure dirs have some hash
591590
hashMap[filePath] = '1';
591+
} else if (item.hash) {
592+
hashMap[filePath] = item.hash;
593+
} else {
594+
// file without hash. this should not happen.
595+
// skip dedup by returning something that will never match
596+
invalidate = true;
592597
}
593598
});
594599

595-
hashString(jsonHash(hashMap), cb);
600+
if (invalidate) {
601+
cb(null, uuid());
602+
} else {
603+
hashString(jsonHash(hashMap), cb);
604+
}
596605
});
597606
};
598607

0 commit comments

Comments
 (0)