diff --git a/lib/persistence.js b/lib/persistence.js index ef4705f..e3f8418 100644 --- a/lib/persistence.js +++ b/lib/persistence.js @@ -288,9 +288,7 @@ Persistence.prototype.loadDatabase = function (cb) { async.waterfall([ function (cb) { Persistence.ensureDirectoryExists(path.dirname(self.filename), function (err) { - fs.exists(self.filename, function (exists) { - if (!exists) { return fs.writeFile(self.filename, '', 'utf8', function (err) { cb(err); }); } - + self.ensureDatafileIntegrity(function (exists) { fs.readFile(self.filename, 'utf8', function (err, rawData) { if (err) { return cb(err); } var treatedData = Persistence.treatRawData(rawData); diff --git a/test/persistence.test.js b/test/persistence.test.js index 4a71da1..1ac0c2c 100644 --- a/test/persistence.test.js +++ b/test/persistence.test.js @@ -254,7 +254,7 @@ describe('Persistence', function () { // This test is a bit complicated since it depends on the time actions take to execute // It may not work as expected on all machines as it is timed for my machine // That's why it is skipped, but all versions of nedb pass this test - describe.only('Prevent dataloss when persisting data', function () { + describe('Prevent dataloss when persisting data', function () { it('Creating a datastore with in memory as true and a bad filename wont cause an error', function () { new Datastore({ filename: 'workspace/bad.db~', inMemoryOnly: true });