From 3647e28d35909f542ada155c729938926b422ad4 Mon Sep 17 00:00:00 2001 From: Jed Parsons <jedp@me.com> Date: Thu, 5 Jul 2012 10:04:02 -0700 Subject: [PATCH] existsSync wrapper to use path (node 0.6.x) or fs (0.8.x) --- lib/db/json.js | 9 ++++++++- lib/i18n.js | 11 +++++++++-- lib/logging.js | 9 ++++++++- lib/metrics.js | 9 ++++++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/db/json.js b/lib/db/json.js index 08bd09d21..0bcfbf8a1 100644 --- a/lib/db/json.js +++ b/lib/db/json.js @@ -16,6 +16,13 @@ logger = require('../logging.js').logger, configuration = require('../configuration.js'), temp = require('temp'); +// existsSync moved from path in 0.6.x to fs in 0.8.x +if (typeof fs.existsSync === 'function') { + var existsSync = fs.existsSync; +} else { + var existsSync = path.existsSync; +} + // a little alias for stringify const ESC = JSON.stringify; @@ -59,7 +66,7 @@ function flush() { function sync() { // the database not existing yet just means its empty, don't log an error - if (fs.existsSync(dbPath)) { + if (existsSync(dbPath)) { try { db = JSON.parse(fs.readFileSync(dbPath)); diff --git a/lib/i18n.js b/lib/i18n.js index 08c9ff7a4..374c87968 100644 --- a/lib/i18n.js +++ b/lib/i18n.js @@ -21,6 +21,13 @@ var logger = require('./logging.js').logger, util = require('util'), fs = require('fs'); +// existsSync moved from path in 0.6.x to fs in 0.8.x +if (typeof fs.existsSync === 'function') { + var existsSync = fs.existsSync; +} else { + var existsSync = path.existsSync; +} + const BIDI_RTL_LANGS = ['ar', 'db-LB', 'fa', 'he']; var mo_cache = {}; @@ -66,8 +73,8 @@ exports.abide = function (options) { default_locale = localeFrom(options.default_lang); mo_cache[l] = { - mo_exists: fs.existsSync(mo_file_path(l)), - json_exists: fs.existsSync(json_file_path(l)), + mo_exists: existsSync(mo_file_path(l)), + json_exists: existsSync(json_file_path(l)), gt: null }; if (l !== debug_locale) { diff --git a/lib/logging.js b/lib/logging.js index 4472cc248..a67a01190 100644 --- a/lib/logging.js +++ b/lib/logging.js @@ -20,12 +20,19 @@ configuration = require("./configuration"), path = require('path'), fs = require('fs'); +// existsSync moved from path in 0.6.x to fs in 0.8.x +if (typeof fs.existsSync === 'function') { + var existsSync = fs.existsSync; +} else { + var existsSync = path.existsSync; +} + // go through the configuration and determine log location var log_path = path.join(configuration.get('var_path'), 'log'); // simple inline function for creation of dirs function mkdir_p(p) { - if (!fs.existsSync(p)) { + if (!existsSync(p)) { mkdir_p(path.dirname(p)); fs.mkdirSync(p, "0755"); } diff --git a/lib/metrics.js b/lib/metrics.js index 6b3f21b51..c5e2cd2b5 100644 --- a/lib/metrics.js +++ b/lib/metrics.js @@ -24,6 +24,13 @@ path = require('path'), fs = require('fs'), urlparse = require('urlparse'); +// existsSync moved from path in 0.6.x to fs in 0.8.x +if (typeof fs.existsSync === 'function') { + var existsSync = fs.existsSync; +} else { + var existsSync = path.existsSync; +} + // go through the configuration and determine log location // for now we only log to one place // FIXME: separate logs depending on purpose? @@ -33,7 +40,7 @@ var LOGGER; // simple inline function for creation of dirs function mkdir_p(p) { - if (!fs.existsSync(p)) { + if (!existsSync(p)) { mkdir_p(path.dirname(p)); fs.mkdirSync(p, "0755"); } -- GitLab