Conditional hashing of osrm libraries
This commit is contained in:
parent
25d3c4b843
commit
bfbb313088
@ -50,21 +50,27 @@ module.exports = function () {
|
||||
};
|
||||
|
||||
var hashExtract = (cb) => {
|
||||
this.hashOfFiles(util.format('%s/osrm-extract%s', this.BIN_PATH, this.EXE), (hash) => {
|
||||
var files = [ util.format('%s/osrm-extract%s', this.BIN_PATH, this.EXE),
|
||||
util.format('%s/libosrm_extract%s', this.BIN_PATH, this.LIB) ];
|
||||
this.hashOfFiles(files, (hash) => {
|
||||
this.binExtractHash = hash;
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
var hashContract = (cb) => {
|
||||
this.hashOfFiles(util.format('%s/osrm-contract%s', this.BIN_PATH, this.EXE), (hash) => {
|
||||
var files = [ util.format('%s/osrm-contract%s', this.BIN_PATH, this.EXE),
|
||||
util.format('%s/libosrm_contract%s', this.BIN_PATH, this.LIB) ];
|
||||
this.hashOfFiles(files, (hash) => {
|
||||
this.binContractHash = hash;
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
var hashRouted = (cb) => {
|
||||
this.hashOfFiles(util.format('%s/osrm-routed%s', this.BIN_PATH, this.EXE), (hash) => {
|
||||
var files = [ util.format('%s/osrm-routed%s', this.BIN_PATH, this.EXE),
|
||||
util.format('%s/libosrm%s', this.BIN_PATH, this.LIB) ];
|
||||
this.hashOfFiles(files, (hash) => {
|
||||
this.binRoutedHash = hash;
|
||||
this.fingerprintRoute = this.hashString(this.binRoutedHash);
|
||||
cb();
|
||||
|
@ -32,10 +32,12 @@ module.exports = function () {
|
||||
if (process.platform.match(/indows.*/)) {
|
||||
this.TERMSIGNAL = 9;
|
||||
this.EXE = '.exe';
|
||||
this.LIB = '.dll';
|
||||
this.QQ = '"';
|
||||
} else {
|
||||
this.TERMSIGNAL = 'SIGTERM';
|
||||
this.EXE = '';
|
||||
this.LIB = '.so';
|
||||
this.QQ = '';
|
||||
}
|
||||
|
||||
|
@ -6,14 +6,19 @@ var d3 = require('d3-queue');
|
||||
module.exports = function () {
|
||||
this.hashOfFiles = (paths, cb) => {
|
||||
paths = Array.isArray(paths) ? paths : [paths];
|
||||
var shasum = crypto.createHash('sha1');
|
||||
var shasum = crypto.createHash('sha1'), hashedFiles = false;
|
||||
|
||||
var q = d3.queue(1);
|
||||
|
||||
var addFile = (path, cb) => {
|
||||
fs.readFile(path, (err, data) => {
|
||||
shasum.update(data);
|
||||
cb(err);
|
||||
if (err && err.code === 'ENOENT') cb(); // ignore non-existing files
|
||||
else if (err) cb(err);
|
||||
else {
|
||||
shasum.update(data);
|
||||
hashedFiles = true;
|
||||
cb();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -21,6 +26,7 @@ module.exports = function () {
|
||||
|
||||
q.awaitAll(err => {
|
||||
if (err) throw new Error('*** Error reading files:', err);
|
||||
if (!hashedFiles) throw new Error('*** No files found: [' + paths.join(', ') + ']');
|
||||
cb(shasum.digest('hex'));
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user