loadDatabase now uses ensureDatafileIntegroty

pull/2/head
Louis Chatriot 11 years ago
parent e609be27de
commit 2a4f55504d
  1. 4
      lib/persistence.js
  2. 2
      test/persistence.test.js

@ -288,9 +288,7 @@ Persistence.prototype.loadDatabase = function (cb) {
async.waterfall([ async.waterfall([
function (cb) { function (cb) {
Persistence.ensureDirectoryExists(path.dirname(self.filename), function (err) { Persistence.ensureDirectoryExists(path.dirname(self.filename), function (err) {
fs.exists(self.filename, function (exists) { self.ensureDatafileIntegrity(function (exists) {
if (!exists) { return fs.writeFile(self.filename, '', 'utf8', function (err) { cb(err); }); }
fs.readFile(self.filename, 'utf8', function (err, rawData) { fs.readFile(self.filename, 'utf8', function (err, rawData) {
if (err) { return cb(err); } if (err) { return cb(err); }
var treatedData = Persistence.treatRawData(rawData); var treatedData = Persistence.treatRawData(rawData);

@ -254,7 +254,7 @@ describe('Persistence', function () {
// This test is a bit complicated since it depends on the time actions take to execute // 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 // 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 // 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 () { 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 }); new Datastore({ filename: 'workspace/bad.db~', inMemoryOnly: true });

Loading…
Cancel
Save