diff --git a/lib/fs.js b/lib/fs.js index a5eb5351acfe..5345afa36b50 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -50,10 +50,6 @@ var O_RDWR = constants.O_RDWR || 0; var O_SYNC = constants.O_SYNC || 0; var O_TRUNC = constants.O_TRUNC || 0; var O_WRONLY = constants.O_WRONLY || 0; -var F_OK = constants.F_OK || 0; -var R_OK = constants.R_OK || 0; -var W_OK = constants.W_OK || 0; -var X_OK = constants.X_OK || 0; var isWindows = process.platform === 'win32'; @@ -186,10 +182,12 @@ fs.Stats.prototype.isSocket = function() { return this._checkModeProperty(constants.S_IFSOCK); }; -fs.F_OK = F_OK; -fs.R_OK = R_OK; -fs.W_OK = W_OK; -fs.X_OK = X_OK; +// don't allow fs.mode to accidentally be overwritten. +['F_OK', 'R_OK', 'W_OK', 'X_OK'].forEach(function(key) { + Object.defineProperty(fs, key, { + enumerable: true, value: constants[key] || 0, writable: false + }); +}); fs.access = function(path, mode, callback) { if (!nullCheck(path, callback)) @@ -197,7 +195,7 @@ fs.access = function(path, mode, callback) { if (typeof mode === 'function') { callback = mode; - mode = F_OK; + mode = fs.F_OK; } else if (typeof callback !== 'function') { throw new TypeError('callback must be a function'); } @@ -212,7 +210,7 @@ fs.accessSync = function(path, mode) { nullCheck(path); if (mode === undefined) - mode = F_OK; + mode = fs.F_OK; else mode = mode | 0;