@@ -7,6 +7,7 @@ var last = require('101/last');
77var isFunction = require ( '101/is-function' ) ;
88var debug = require ( 'debug' ) ( 'runnable-api:infra-code-version:model' ) ;
99var regexpQuote = require ( 'regexp-quote' ) ;
10+ var crypto = require ( 'crypto' ) ;
1011
1112var path = require ( 'path' ) ;
1213var join = path . join ;
@@ -215,9 +216,13 @@ InfraCodeVersionSchema.methods.createFs = function (data, cb) {
215216 infraCodeVersion . files . push ( s3Data ) ;
216217 var fileData = infraCodeVersion . files . pop ( ) . toJSON ( ) ;
217218 var fileKey , dirKey ;
219+ var attrs = {
220+ edited : true
221+ } ;
218222 if ( last ( fileData . Key ) === '/' ) {
219223 fileKey = fileData . Key . slice ( 0 , - 1 ) ;
220224 dirKey = fileData . Key ;
225+ attrs . hash = hashString ( data . body . toString ( ) ) ;
221226 }
222227 else {
223228 fileKey = fileData . Key ;
@@ -231,9 +236,7 @@ InfraCodeVersionSchema.methods.createFs = function (data, cb) {
231236 $push : {
232237 files : fileData
233238 } ,
234- $set : {
235- edited : true
236- }
239+ $set : attrs
237240 } , function ( err , numUpdated ) {
238241 if ( err ) {
239242 cb ( err ) ;
@@ -287,6 +290,7 @@ InfraCodeVersionSchema.methods.updateFile = function (fullpath, body, cb) {
287290 } , {
288291 $set : {
289292 'files.$' : file . toJSON ( ) ,
293+ 'hash' : hashString ( body . toString ( ) ) ,
290294 edited : true
291295 }
292296 } , function ( err ) {
@@ -546,4 +550,7 @@ InfraCodeVersionSchema.methods.copyFilesFromSource = function (sourceInfraCodeVe
546550 }
547551} ;
548552
553+ function hashString ( data ) {
554+ return crypto . createHash ( 'md5' ) . update ( data . toString ( ) . trim ( ) ) . digest ( 'hex' ) ;
555+ }
549556var InfraCodeVersion = module . exports = mongoose . model ( 'InfraCodeVersion' , InfraCodeVersionSchema ) ;
0 commit comments