diff options
Diffstat (limited to 'deps/npm/lib/doctor/check-files-permission.js')
-rw-r--r-- | deps/npm/lib/doctor/check-files-permission.js | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/deps/npm/lib/doctor/check-files-permission.js b/deps/npm/lib/doctor/check-files-permission.js index 74393596f6..50014fd232 100644 --- a/deps/npm/lib/doctor/check-files-permission.js +++ b/deps/npm/lib/doctor/check-files-permission.js @@ -9,12 +9,12 @@ var fileCompletion = require('../utils/completion/file-completion.js') function checkFilesPermission (root, mask, cb) { if (process.platform === 'win32') return cb(null, true) getUid(npm.config.get('user'), npm.config.get('group'), function (e, uid, gid) { + var tracker = log.newItem('checkFilePermissions', 1) if (e) { tracker.finish() tracker.warn('checkFilePermissions', 'Error looking up user and group:', e) return cb(e) } - var tracker = log.newItem('checkFilePermissions', 1) tracker.info('checkFilePermissions', 'Building file list of ' + root) fileCompletion(root, '.', Infinity, function (e, files) { if (e) { @@ -38,14 +38,16 @@ function checkFilesPermission (root, mask, cb) { tracker.completeWork(1) if (e) return next(e) if (!stat.isFile()) return next() - var mode = stat.mode - var isGroup = stat.gid ? stat.gid === gid : true - var isUser = stat.uid ? stat.uid === uid : true - if ((mode & parseInt('000' + mask, 8))) return next() - if ((isGroup && mode & parseInt('00' + mask + '0', 8))) return next() - if ((isUser && mode & parseInt('0' + mask + '00', 8))) return next() - tracker.error('checkFilePermissions', 'Missing permissions on (' + isGroup + ', ' + isUser + ', ' + mode + ')', file) - return next(new Error('Missing permissions for ' + file)) + // 6 = fs.constants.R_OK | fs.constants.W_OK + // constants aren't available on v4 + fs.access(file, 6, (err) => { + if (err) { + tracker.error('checkFilePermissions', `Missing permissions on ${file}`) + return next(new Error('Missing permissions for ' + file)) + } else { + return next() + } + }) }) } }) |