Skip to content

Commit

Permalink
FIX: Fix missing checksum comparison from reconcile since now we use …
Browse files Browse the repository at this point in the history
…mtime and size by default.

Old mode using checkSum can still be used by passing the `useCheckSum` parameter to the `create` or `createFromFile` methods.
  • Loading branch information
royriojas committed Feb 4, 2019
1 parent 875b3e1 commit e858aa9
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,23 @@ module.exports = {
normalizedEntries = { };
cache.destroy();
},

_getMetaForFileUsingCheckSum: function ( cacheEntry ) {
var contentBuffer = fs.readFileSync( cacheEntry.key );
var hash = this.getHash( contentBuffer );
var meta = Object.assign( cacheEntry.meta, { hash: hash } );
return meta;
},

_getMetaForFileUsingMtimeAndSize: function ( cacheEntry ) {
var stat = fs.statSync( cacheEntry.key );
var meta = Object.assign( cacheEntry.meta, {
size: stat.size,
mtime: stat.mtime.getTime()
} );
return meta;
},

/**
* Sync the files and persist them to the cache
* @method reconcile
Expand All @@ -240,20 +257,18 @@ module.exports = {

var entries = normalizedEntries;
var keys = Object.keys( entries );
var me = this;

if ( keys.length === 0 ) {
return;
}

var me = this;

keys.forEach( function ( entryName ) {
var cacheEntry = entries[ entryName ];

try {
var contentBuffer = fs.readFileSync( cacheEntry.key );
var hash = me.getHash( contentBuffer );
var meta = Object.assign( cacheEntry.meta, { hash: hash } );

var meta = useChecksum ? me._getMetaForFileUsingCheckSum( cacheEntry ) : me._getMetaForFileUsingMtimeAndSize( cacheEntry );
cache.setKey( entryName, meta );
} catch (err) {
// if the file does not exists we don't save it
Expand Down

0 comments on commit e858aa9

Please sign in to comment.