From 59f8330db477cc78ea05bc53582fab3042bdf3a8 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Tue, 19 Sep 2017 09:32:52 +0200 Subject: [PATCH] update cache mechanism to handle forced profile --- features/lib/hash.js | 4 ++-- features/support/cache.js | 7 +++++-- features/support/env.js | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/features/lib/hash.js b/features/lib/hash.js index 57563e3da..32f0c1c28 100644 --- a/features/lib/hash.js +++ b/features/lib/hash.js @@ -20,11 +20,11 @@ module.exports = { }); }, - hashOfFile: (path, cb) => { + hashOfFile: (path, additional_content, cb) => { fs.readFile(path, (err, result) => { if (err) return cb(err); let checksum = crypto.createHash('md5'); - checksum.update(result); + checksum.update(result + (additional_content || "") ); cb(null, checksum.digest('hex')); }); } diff --git a/features/support/cache.js b/features/support/cache.js index 96a81404d..c30f66a00 100644 --- a/features/support/cache.js +++ b/features/support/cache.js @@ -28,13 +28,16 @@ module.exports = function() { let uri = feature.getUri(); // setup cache for feature data - hash.hashOfFile(uri, (err, hash) => { + // if OSRM_PROFILE is set to force a specific profile, then + // include the profile name in the hash of the profile file + hash.hashOfFile(uri, this.OSRM_PROFILE, (err, hash) => { if (err) return callback(err); // shorten uri to be realtive to 'features/' let featurePath = path.relative(path.resolve('./features'), uri); // bicycle/bollards/{HASH}/ - let featureID = path.join(featurePath, hash); + let featureID = path.join(featurePath, hash); + let featureCacheDirectory = this.getFeatureCacheDirectory(featureID); let featureProcessedCacheDirectory = this.getFeatureProcessedCacheDirectory(featureCacheDirectory, this.osrmHash); this.featureIDs[uri] = featureID; diff --git a/features/support/env.js b/features/support/env.js index 9fdacc383..3090fc708 100644 --- a/features/support/env.js +++ b/features/support/env.js @@ -45,7 +45,7 @@ module.exports = function () { this.OSRM_PORT = process.env.OSRM_PORT && parseInt(process.env.OSRM_PORT) || 5000; this.HOST = 'http://127.0.0.1:' + this.OSRM_PORT; - this.OSRM_PROFILE = process.env.PROFILE + this.OSRM_PROFILE = process.env.OSRM_PROFILE if (this.PLATFORM_WINDOWS) { this.TERMSIGNAL = 9;