Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. /*
  2. ** Saves `file` object into `path`.
  3. ** Will attempt backup first, and may reload a backup on errors
  4. */
  5. save: function(path, file) {
  6. this.backup(path, file, () => {
  7. FS.writeFile(path, JSON.stringify(file), (err) => {
  8. if (err) {
  9. this.log(err, this.LogTypes.ERROR);
  10. this.log(`Something wrong happened, FS.writeFile operation on '${path}' failed!`, this.LogTypes.ERROR);
  11. if (FS.existsSync(`${path}.bak`)) {
  12. this.log(`Reverting '${path}' to backup!`, this.LogTypes.DATABASE);
  13. FS.copyFile(`${path}.bak`, `${path}`, (err) => {
  14. if (err) {
  15. this.log(err, this.LogTypes.ERROR);
  16. this.log(`Unable to restore backup from '${path}.bak'! '${path} may have been corrupted or destroyed!'`, this.LogTypes.ERROR);
  17. } else this.log(`'${path}' has been restored to the latest backup successfully.`, this.LogTypes.DATABASE);
  18. });
  19. } 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);
  20. } else {
  21. this.log(`'${path}' has been saved successfully!`, this.LogTypes.DATABASE);
  22. }
  23. });
  24. });
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement