Skip to content

Commit

Permalink
Merge pull request #3793 from dailyrandomphoto/fix-save-database
Browse files Browse the repository at this point in the history
fix(save_database): should not clear database when use 'hexo new', 'hexo --help'
  • Loading branch information
curbengh committed Nov 2, 2019
2 parents 764f6d2 + bc9748f commit 0d8a832
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/plugins/filter/before_exit/save_database.js
@@ -1,7 +1,7 @@
'use strict';

function saveDatabaseFilter() {
if (!this.env.init) return;
if (!this.env.init || !this._dbLoaded) return;

return this.database.save().then(() => {
this.log.debug('Database saved');
Expand Down
11 changes: 11 additions & 0 deletions test/scripts/filters/save_database.js
Expand Up @@ -11,6 +11,7 @@ describe('Save database', () => {

it('default', () => {
hexo.env.init = true;
hexo._dbLoaded = true;

return saveDatabase().then(() => fs.exists(dbPath)).then(exist => {
exist.should.be.true;
Expand All @@ -20,6 +21,16 @@ describe('Save database', () => {

it('do nothing if hexo is not initialized', () => {
hexo.env.init = false;
hexo._dbLoaded = true;

return saveDatabase().then(() => fs.exists(dbPath)).then(exist => {
exist.should.be.false;
});
});

it('do nothing if database is not loaded', () => {
hexo.env.init = true;
hexo._dbLoaded = false;

return saveDatabase().then(() => fs.exists(dbPath)).then(exist => {
exist.should.be.false;
Expand Down

0 comments on commit 0d8a832

Please sign in to comment.