diff --git a/lib/cli/cacheUtils.js b/lib/cli/cacheUtils.js index 84b3c2799..c589add65 100644 --- a/lib/cli/cacheUtils.js +++ b/lib/cli/cacheUtils.js @@ -157,7 +157,7 @@ function readCommitId(context, cb) { function clear() { var isDeleted = false; - if (fs.existsSync(utils.azureDir())) { + if (utils.pathExistsSync(utils.azureDir())) { var cacheFiles = fs.readdirSync(utils.azureDir()); for (var i = 0; i < cacheFiles.length; ++i) { if (/sites[.].+[.]json/.test(cacheFiles[i]) diff --git a/lib/cli/cli.js b/lib/cli/cli.js index df5db0eb2..ea1fbe008 100644 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -24,16 +24,12 @@ var colors = require('colors'); var eyes = require('eyes'); var Table = require('easy-table'); +var utils = require('./utils'); + require('./patch-winston'); var istty1 = tty.isatty(1); -// Temporary fix for node version < 0.8, starting from v0.8 -// path.existsSync has been deprecated -if (!fs.existsSync) { - fs.existsSync = path.existsSync; -} - function recordError(err) { if (err && err.stack) { try { @@ -832,7 +828,7 @@ function harvestModules() { results = results.filter(function (item) { item.packagePath = path.join(item.modulePath, 'package.json'); - item.packageStat = fs.existsSync(item.packagePath) ? fs.statSync(item.packagePath) : undefined; + item.packageStat = utils.pathExistsSync(item.packagePath) ? fs.statSync(item.packagePath) : undefined; return item.packageStat && item.packageStat.isFile(); }); diff --git a/lib/cli/commands/config.js b/lib/cli/commands/config.js index c899ebf72..8843b575e 100644 --- a/lib/cli/commands/config.js +++ b/lib/cli/commands/config.js @@ -90,7 +90,7 @@ exports.init = function (cli) { var cfg = {}; log.silly('Reading config', azureConfigPath); - if (fs.existsSync(azureConfigPath)) { + if (utils.pathExistsSync(azureConfigPath)) { try { cfg = JSON.parse(fs.readFileSync(azureConfigPath)); } catch (err) { diff --git a/lib/cli/commands/log_.js b/lib/cli/commands/log_.js index bb7ba155b..a576d48db 100644 --- a/lib/cli/commands/log_.js +++ b/lib/cli/commands/log_.js @@ -55,7 +55,7 @@ exports.init = function (cli) { context.path = path.join(context.path, 'diagnostics.zip'); } - if (path.existsSync(context.path)) { + if (utils.pathExistsSync(context.path)) { if (!site.confirm('Replace existing ' + context.path + '? (y/n) ', _)) { return; } diff --git a/lib/cli/commands/site_.js b/lib/cli/commands/site_.js index 12196c0e3..a7e23e96e 100644 --- a/lib/cli/commands/site_.js +++ b/lib/cli/commands/site_.js @@ -232,7 +232,7 @@ exports.init = function (cli) { log.info('Executing `git init`'); exec('git init', _); - if (!path.existsSync('.gitignore')) { + if (!utils.pathExistsSync('.gitignore')) { log.info('Creating default .gitignore file'); fs.writeFile('.gitignore', 'node_modules\nazure_error', _); } @@ -242,7 +242,7 @@ exports.init = function (cli) { function copyIisNodeWhenServerJsPresent(_) { log.silly('copyWebConfigWhenServerJsPresent'); - if (!path.existsSync('iisnode.yml') && (path.existsSync('server.js') || path.existsSync('app.js'))) { + if (!utils.pathExistsSync('iisnode.yml') && (utils.pathExistsSync('server.js') || utils.pathExistsSync('app.js'))) { log.info('Creating default iisnode.yml file'); var sourcePath = path.join(__dirname, '../templates/node/iisnode.yml'); fs.writeFile('iisnode.yml', fs.readFile(sourcePath, _), _); diff --git a/lib/cli/utils.js b/lib/cli/utils.js index 3d6707656..7d3119367 100644 --- a/lib/cli/utils.js +++ b/lib/cli/utils.js @@ -428,7 +428,7 @@ exports.azureDir = function () { var dir = process.env.AZURE_CONFIG_DIR || path.join(homeFolder(), '.azure'); - if (!fs.existsSync(dir)) { + if (!exports.pathExistsSync(dir)) { fs.mkdirSync(dir, 502); // 0766 } @@ -455,3 +455,8 @@ exports.getHostNameSuffix = function () { return process.env.AZURE_HOSTNAME_SUFFIX || constants.DEFAULT_HOSTNAME_SUFFIX; }; + +exports.pathExistsSync = function (path) { + var obj = fs.existsSync ? fs : path; + return obj.existsSync.apply(obj, arguments); +}; \ No newline at end of file diff --git a/lib/services/blob/blobservice.js b/lib/services/blob/blobservice.js index 6177c9d10..2a83c6fde 100644 --- a/lib/services/blob/blobservice.js +++ b/lib/services/blob/blobservice.js @@ -1260,7 +1260,7 @@ BlobService.prototype.getBlobToFile = function (container, blob, localFilename, this.getBlobToStream(container, blob, writeStream, options, function (error, responseBlob, response) { if (error) { - if (path.existsSync(localFilename)) { + if (azureutil.pathExistsSync(localFilename)) { // make sure writeStream is closed / destroyed to avoid locking issues if (writeStream.close) { writeStream.close(); diff --git a/lib/util/util.js b/lib/util/util.js index 53968a44b..0271e3e68 100644 --- a/lib/util/util.js +++ b/lib/util/util.js @@ -213,4 +213,9 @@ exports.stringIsDate = function(date) { */ exports.merge = function () { return _.extend.apply(this, arguments); +}; + +exports.pathExistsSync = function (path) { + var obj = fs.existsSync ? fs : path; + return obj.existsSync.apply(obj, arguments); }; \ No newline at end of file diff --git a/test/serviceruntime/roleenvironment-tests.js b/test/serviceruntime/roleenvironment-tests.js index 244831d75..fd77ca44e 100644 --- a/test/serviceruntime/roleenvironment-tests.js +++ b/test/serviceruntime/roleenvironment-tests.js @@ -82,12 +82,6 @@ function setupGoalStateEndpoint () { suite('roleenvironment-tests', function () { setup(function (done) { - // Temporary fix for node version < 0.8, starting from v0.8 - // path.existsSync has been deprecated. - if (!fs.existsSync) { - fs.existsSync = path.existsSync; - } - // Set windows azure runtime endpoint originalWaRuntimeEndpoint = process.env['WaRuntimeEndpoint']; process.env['WaRuntimeEndpoint'] = versionsEndpointPath; @@ -111,19 +105,19 @@ suite('roleenvironment-tests', function () { runtimeKernel.protocol1RuntimeGoalStateClient.currentEnvironmentData = null; runtimeKernel.protocol1RuntimeGoalStateClient.currentGoalState = null; - if (fs.existsSync(versionsEndpointPath)) { + if (azureutil.pathExistsSync(versionsEndpointPath)) { fs.unlinkSync(versionsEndpointPath); } - if (fs.existsSync(goalStatePath)) { + if (azureutil.pathExistsSync(goalStatePath)) { fs.unlinkSync(goalStatePath); } - if (fs.existsSync(currentStatePath)) { + if (azureutil.pathExistsSync(currentStatePath)) { fs.unlinkSync(currentStatePath); } - if (fs.existsSync(roleEnvironmentPath)) { + if (azureutil.pathExistsSync(roleEnvironmentPath)) { fs.unlinkSync(roleEnvironmentPath); }