File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ var regexpQuote = require('regexp-quote');
1010var bcrypt = require ( 'bcrypt' ) ;
1111var jsonHash = require ( 'json-stable-stringify' ) ;
1212var dogstatsd = require ( 'models/datadog' ) ;
13+ var uuid = require ( 'uuid' ) ;
1314
1415var path = require ( 'path' ) ;
1516var 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
You can’t perform that action at this time.
0 commit comments