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