diff --git a/lib/API/Startup.js b/lib/API/Startup.js index f77ca5167..b96877fe8 100644 --- a/lib/API/Startup.js +++ b/lib/API/Startup.js @@ -7,6 +7,7 @@ var debug = require('debug')('pm2:cli:startup'); var chalk = require('chalk'); var path = require('path'); var fs = require('fs'); +const fsExtra = require('fs-extra'); var async = require('async'); var exec = require('child_process').exec; var Common = require('../Common.js'); @@ -396,7 +397,7 @@ module.exports = function(CLI) { // Back up dump file try { if (fs.existsSync(cst.DUMP_FILE_PATH)) { - fs.copyFileSync(cst.DUMP_FILE_PATH, cst.DUMP_BACKUP_FILE_PATH); + fsExtra.copySync(cst.DUMP_FILE_PATH, cst.DUMP_BACKUP_FILE_PATH); } } catch (e) { console.error(e.stack || e); @@ -411,7 +412,7 @@ module.exports = function(CLI) { try { // try to backup file if(fs.existsSync(cst.DUMP_BACKUP_FILE_PATH)) { - fs.copyFileSync(cst.DUMP_BACKUP_FILE_PATH, cst.DUMP_FILE_PATH); + fsExtra.copySync(cst.DUMP_BACKUP_FILE_PATH, cst.DUMP_FILE_PATH); } } catch (e) { // don't keep broken file diff --git a/lib/God/ActionMethods.js b/lib/God/ActionMethods.js index 1df6b159c..1556a1652 100644 --- a/lib/God/ActionMethods.js +++ b/lib/God/ActionMethods.js @@ -12,6 +12,7 @@ */ var fs = require('fs'); +const fsExtra = require('fs-extra'); var path = require('path'); var async = require('async'); var os = require('os'); @@ -155,7 +156,7 @@ module.exports = function(God) { // Back up dump file try { if (fs.existsSync(cst.DUMP_FILE_PATH)) { - fs.copyFileSync(cst.DUMP_FILE_PATH, cst.DUMP_BACKUP_FILE_PATH); + fsExtra.copySync(cst.DUMP_FILE_PATH, cst.DUMP_BACKUP_FILE_PATH); } } catch (e) { console.error(e.stack || e); @@ -169,7 +170,7 @@ module.exports = function(God) { try { // try to backup file if(fs.existsSync(cst.DUMP_BACKUP_FILE_PATH)) { - fs.copyFileSync(cst.DUMP_BACKUP_FILE_PATH, cst.DUMP_FILE_PATH); + fsExtra.copySync(cst.DUMP_BACKUP_FILE_PATH, cst.DUMP_FILE_PATH); } } catch (e) { // don't keep broken file diff --git a/package.json b/package.json index 3bd207d6d..4acaa133d 100644 --- a/package.json +++ b/package.json @@ -169,6 +169,7 @@ "debug": "^3.0", "eventemitter2": "5.0.1", "fclone": "1.0.11", + "fs-extra": "^5.0.0", "mkdirp": "0.5.1", "moment": "^2.19", "needle": "^2.2.0",