mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-20 11:48:30 -06:00
SEARCH-563
- Deleting the tmp files
This commit is contained in:
parent
f4ff287547
commit
77ac2102d4
@ -10,6 +10,9 @@ let Transform = stream.Transform;
|
|||||||
let util = require('util');
|
let util = require('util');
|
||||||
let crypto = require('crypto');
|
let crypto = require('crypto');
|
||||||
|
|
||||||
|
const log = require('../log.js');
|
||||||
|
const logLevels = require('../enums/logLevels.js');
|
||||||
|
|
||||||
let KEY_LENGTH = 32; // bytes
|
let KEY_LENGTH = 32; // bytes
|
||||||
let GCM_NONCE_LENGTH = 12; //bytes
|
let GCM_NONCE_LENGTH = 12; //bytes
|
||||||
let GCM_MAC_LENGTH = 16; //bytes
|
let GCM_MAC_LENGTH = 16; //bytes
|
||||||
@ -151,7 +154,8 @@ DecryptionStream.prototype._transform = function(chunk, enc, cb) {
|
|||||||
DecryptionStream.prototype._flush = function(cb) {
|
DecryptionStream.prototype._flush = function(cb) {
|
||||||
let mac = pullOutMac(this._cipherTextChunks);
|
let mac = pullOutMac(this._cipherTextChunks);
|
||||||
if (!mac) {
|
if (!mac) {
|
||||||
return this.emit('error', new Error('Decryption failed: bad cipher text.'));
|
log.send(logLevels.ERROR, 'Crypto: Decryption failed: bad cipher text.');
|
||||||
|
return cb();
|
||||||
}
|
}
|
||||||
this._decipher.setAuthTag(mac);
|
this._decipher.setAuthTag(mac);
|
||||||
let decrypted = this._cipherTextChunks.map(function(item) {
|
let decrypted = this._cipherTextChunks.map(function(item) {
|
||||||
@ -160,6 +164,7 @@ DecryptionStream.prototype._flush = function(cb) {
|
|||||||
try {
|
try {
|
||||||
this._decipher.final();
|
this._decipher.final();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
log.send(logLevels.ERROR, 'Crypto: Decryption Failed: ' + e);
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
decrypted.forEach(function(item) {
|
decrypted.forEach(function(item) {
|
||||||
|
@ -56,17 +56,32 @@ class Crypto {
|
|||||||
let config = {
|
let config = {
|
||||||
key: key
|
key: key
|
||||||
};
|
};
|
||||||
const encrypt = crypto.encrypt(config);
|
let encrypt;
|
||||||
|
try {
|
||||||
|
encrypt = crypto.encrypt(config);
|
||||||
|
} catch (e) {
|
||||||
|
log.send(logLevels.ERROR, 'Error decrypting : ' + e);
|
||||||
|
if (fs.existsSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`)) {
|
||||||
|
fs.unlinkSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`);
|
||||||
|
}
|
||||||
|
reject();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let encryptionProcess = input.pipe(encrypt).pipe(outputEncryption);
|
let encryptionProcess = input.pipe(encrypt).pipe(outputEncryption);
|
||||||
|
|
||||||
encryptionProcess.on('finish', (err) => {
|
encryptionProcess.on('finish', (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
log.send(logLevels.ERROR, 'Crypto: Error while encrypting the compressed file: ' + err);
|
log.send(logLevels.ERROR, 'Crypto: Error while encrypting the compressed file: ' + err);
|
||||||
|
if (fs.existsSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`)) {
|
||||||
|
fs.unlinkSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`);
|
||||||
|
}
|
||||||
reject(new Error(err));
|
reject(new Error(err));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fs.unlinkSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`);
|
if (fs.existsSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`)) {
|
||||||
|
fs.unlinkSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`);
|
||||||
|
}
|
||||||
resolve('Success');
|
resolve('Success');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -92,7 +107,17 @@ class Crypto {
|
|||||||
let config = {
|
let config = {
|
||||||
key: this.key
|
key: this.key
|
||||||
};
|
};
|
||||||
const decrypt = crypto.decrypt(config);
|
let decrypt;
|
||||||
|
try {
|
||||||
|
decrypt = crypto.decrypt(config);
|
||||||
|
} catch (e) {
|
||||||
|
log.send(logLevels.ERROR, 'Error decrypting : ' + e);
|
||||||
|
if (fs.existsSync(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`)) {
|
||||||
|
fs.unlinkSync(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`);
|
||||||
|
}
|
||||||
|
reject();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let decryptionProcess = input.pipe(decrypt).pipe(output);
|
let decryptionProcess = input.pipe(decrypt).pipe(output);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user