Skip to content

Commit

Permalink
fix: #3485 fix issue when there is empty dump file
Browse files Browse the repository at this point in the history
  • Loading branch information
wallet77 committed Mar 2, 2018
1 parent beb6e48 commit f2523f6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
26 changes: 21 additions & 5 deletions lib/API/Startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
19 changes: 14 additions & 5 deletions lib/God/ActionMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down

0 comments on commit f2523f6

Please sign in to comment.