mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
fix: #3485 fix issue when there is empty dump file
This commit is contained in:
parent
beb6e48787
commit
f2523f6a6b
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user