Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** Saves `file` object into `path`.
- ** Will attempt backup first, and may reload a backup on errors
- */
- save: function(path, file) {
- this.backup(path, file, () => {
- FS.writeFile(path, JSON.stringify(file), (err) => {
- if (err) {
- this.log(err, this.LogTypes.ERROR);
- this.log(`Something wrong happened, FS.writeFile operation on '${path}' failed!`, this.LogTypes.ERROR);
- if (FS.existsSync(`${path}.bak`)) {
- this.log(`Reverting '${path}' to backup!`, this.LogTypes.DATABASE);
- FS.copyFile(`${path}.bak`, `${path}`, (err) => {
- if (err) {
- this.log(err, this.LogTypes.ERROR);
- this.log(`Unable to restore backup from '${path}.bak'! '${path} may have been corrupted or destroyed!'`, this.LogTypes.ERROR);
- } else this.log(`'${path}' has been restored to the latest backup successfully.`, this.LogTypes.DATABASE);
- });
- } else this.log(`Backup for '${path}' was not found, cannot restore backup!nPlease make sure that ${path} is not damaged, or is an operation-critical file, and restart the bot.`, this.LogTypes.ERROR);
- } else {
- this.log(`'${path}' has been saved successfully!`, this.LogTypes.DATABASE);
- }
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement