From 6b9711cb70c45c67224f4a12b371559883c78f19 Mon Sep 17 00:00:00 2001 From: Stefan Date: Mon, 20 Jun 2016 00:22:29 +0200 Subject: Fixed path check --- src/node/hooks/i18n.js | 2 +- src/node/utils/caching_middleware.js | 3 +-- src/node/utils/path_exists.js | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/node/utils/path_exists.js diff --git a/src/node/hooks/i18n.js b/src/node/hooks/i18n.js index d0be2d6f..1b5b354d 100644 --- a/src/node/hooks/i18n.js +++ b/src/node/hooks/i18n.js @@ -5,7 +5,7 @@ var languages = require('languages4translatewiki') , npm = require('npm') , plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins.js').plugins , semver = require('semver') - , existsSync = fs.statSync || fs.existsSync || path.existsSync + , existsSync = require('../utils/path_exists') ; diff --git a/src/node/utils/caching_middleware.js b/src/node/utils/caching_middleware.js index 91b8143b..65fe5d2f 100644 --- a/src/node/utils/caching_middleware.js +++ b/src/node/utils/caching_middleware.js @@ -21,8 +21,7 @@ var path = require('path'); var zlib = require('zlib'); var settings = require('./Settings'); var semver = require('semver'); - -var existsSync = fs.statSync || fs.existsSync || path.existsSync; +var existsSync = require('./path_exists'); var CACHE_DIR = path.normalize(path.join(settings.root, 'var/')); CACHE_DIR = existsSync(CACHE_DIR) ? CACHE_DIR : undefined; diff --git a/src/node/utils/path_exists.js b/src/node/utils/path_exists.js new file mode 100644 index 00000000..c2d43f6c --- /dev/null +++ b/src/node/utils/path_exists.js @@ -0,0 +1,15 @@ +var fs = require('fs'); + +var check = function(path) { + var existsSync = fs.statSync || fs.existsSync || path.existsSync; + + var result; + try { + result = existsSync(path); + } catch (e) { + result = false; + } + return result; +} + +module.exports = check; -- cgit v1.2.3