From 583b0b7ce7bb463685fc18e316ca8009952e73bb Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Thu, 18 Aug 2011 12:23:52 +0300
Subject: [PATCH] json database should store authdb.json into configured  by
 default

---
 browserid/lib/db_json.js | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/browserid/lib/db_json.js b/browserid/lib/db_json.js
index 608476895..a38da9d76 100644
--- a/browserid/lib/db_json.js
+++ b/browserid/lib/db_json.js
@@ -42,14 +42,14 @@ const
 path = require('path'),
 fs = require('fs'),
 secrets = require('./secrets'),
-jsel = require('JSONSelect');
+jsel = require('JSONSelect'),
+logger = require('../../libs/logging.js').logger,
+configuration = require('../../libs/configuration.js');
 
 // a little alias for stringify
 const ESC = JSON.stringify;
 
-var VAR_DIR = path.join(path.dirname(__dirname), "var");
-
-var dbPath = path.join(VAR_DIR, "authdb.json");
+var dbPath = path.join(configuration.get('var_path'), "authdb.json");
 
 /* The JSON database. The structure is thus:
  *  [
@@ -75,7 +75,11 @@ var stagedEmails = { };
 var staged = { };
 
 function flush() {
-  fs.writeFileSync(dbPath, JSON.stringify(db));
+  try {
+    var e = fs.writeFileSync(dbPath, JSON.stringify(db));
+  } catch (e) {
+    logger.error("Cannot save database to " + dbPath);
+  }
 }
 
 // when should a key created right now expire?
-- 
GitLab