fix: #3485 fix issue when there is empty dump file

This commit is contained in:
vince 2018-03-02 10:22:23 +01:00
parent beb6e48787
commit f2523f6a6b
2 changed files with 35 additions and 10 deletions

View File

@ -371,13 +371,26 @@ module.exports = function(CLI) {
* @return
*/
function fin(err) {
// try to fix issues with empty dump file
// like #3485
if (env_arr.length === 0) {
// if no process in list don't modify dump file
// process list should not be empty
if(cb) {
return cb(null, {success: true});
} else {
Common.printOut(cst.PREFIX_MSG + 'Nothing to save !!!');
Common.printOut(cst.PREFIX_MSG + 'In this case we keep old dump file. To clear dump file you can delete it manually !');
that.exitCli(cst.SUCCESS_EXIT);
return;
}
}
// Back up dump file
try {
if (fs.existsSync(cst.DUMP_FILE_PATH)) {
if (fs.existsSync(cst.DUMP_BACKUP_FILE_PATH)) {
fs.unlinkSync(cst.DUMP_BACKUP_FILE_PATH);
}
fs.renameSync(cst.DUMP_FILE_PATH, cst.DUMP_BACKUP_FILE_PATH);
fs.copyFileSync(cst.DUMP_FILE_PATH, cst.DUMP_BACKUP_FILE_PATH);
}
} catch (e) {
console.error(e.stack || e);
@ -390,8 +403,11 @@ module.exports = function(CLI) {
} catch (e) {
console.error(e.stack || e);
try {
fs.unlinkSync(cst.DUMP_FILE_PATH);
// try to backup file
fs.copyFileSync(cst.DUMP_BACKUP_FILE_PATH, cst.DUMP_FILE_PATH);
} catch (e) {
// don't keep broken file
fs.unlinkSync(cst.DUMP_FILE_PATH);
console.error(e.stack || e);
}
Common.printOut(cst.PREFIX_MSG_ERR + 'Failed to save dump file in %s', cst.DUMP_FILE_PATH);

View File

@ -137,13 +137,19 @@ module.exports = function(God) {
}
function fin(err) {
// try to fix issues with empty dump file
// like #3485
if (process_list.length === 0) {
// if no process in list don't modify dump file
// process list should not be empty
return cb(null, {success:true, process_list: process_list});
}
// Back up dump file
try {
if (fs.existsSync(cst.DUMP_FILE_PATH)) {
if (fs.existsSync(cst.DUMP_BACKUP_FILE_PATH)) {
fs.unlinkSync(cst.DUMP_BACKUP_FILE_PATH);
}
fs.renameSync(cst.DUMP_FILE_PATH, cst.DUMP_BACKUP_FILE_PATH);
fs.copyFileSync(cst.DUMP_FILE_PATH, cst.DUMP_BACKUP_FILE_PATH);
}
} catch (e) {
console.error(e.stack || e);
@ -155,8 +161,11 @@ module.exports = function(God) {
} catch (e) {
console.error(e.stack || e);
try {
fs.unlinkSync(cst.DUMP_FILE_PATH);
// try to backup file
fs.copyFileSync(cst.DUMP_BACKUP_FILE_PATH, cst.DUMP_FILE_PATH);
} catch (e) {
// don't keep broken file
fs.unlinkSync(cst.DUMP_FILE_PATH);
console.error(e.stack || e);
}
}