@@ -10,7 +10,6 @@ const semver = require('semver')
10
10
const { promisify } = require ( 'util' )
11
11
const log = require ( '../utils/log-shim.js' )
12
12
const ansiTrim = require ( '../utils/ansi-trim.js' )
13
- const isWindows = require ( '../utils/is-windows.js' )
14
13
const ping = require ( '../utils/ping.js' )
15
14
const {
16
15
registry : { default : defaultRegistry } ,
@@ -55,32 +54,36 @@ class Doctor extends BaseCommand {
55
54
[ 'node -v' , 'getLatestNodejsVersion' , [ ] ] ,
56
55
[ 'npm config get registry' , 'checkNpmRegistry' , [ ] ] ,
57
56
[ 'which git' , 'getGitPath' , [ ] ] ,
58
- ...( isWindows
57
+ ...( process . platform === 'win32'
59
58
? [ ]
60
59
: [
61
- [ 'Perms check on cached files' , 'checkFilesPermission' , [ this . npm . cache , true , R_OK ] ] ,
62
60
[
61
+ 'Perms check on cached files' ,
62
+ 'checkFilesPermission' ,
63
+ [ this . npm . cache , true , R_OK ] ,
64
+ ] , [
63
65
'Perms check on local node_modules' ,
64
66
'checkFilesPermission' ,
65
- [ this . npm . localDir , true ] ,
66
- ] ,
67
- [
67
+ [ this . npm . localDir , true , R_OK | W_OK , true ] ,
68
+ ] , [
68
69
'Perms check on global node_modules' ,
69
70
'checkFilesPermission' ,
70
- [ this . npm . globalDir , false ] ,
71
- ] ,
72
- [
71
+ [ this . npm . globalDir , false , R_OK ] ,
72
+ ] , [
73
73
'Perms check on local bin folder' ,
74
74
'checkFilesPermission' ,
75
- [ this . npm . localBin , false , R_OK | W_OK | X_OK ] ,
76
- ] ,
77
- [
75
+ [ this . npm . localBin , false , R_OK | W_OK | X_OK , true ] ,
76
+ ] , [
78
77
'Perms check on global bin folder' ,
79
78
'checkFilesPermission' ,
80
79
[ this . npm . globalBin , false , X_OK ] ,
81
80
] ,
82
81
] ) ,
83
- [ 'Verify cache contents' , 'verifyCachedFiles' , [ this . npm . flatOptions . cache ] ] ,
82
+ [
83
+ 'Verify cache contents' ,
84
+ 'verifyCachedFiles' ,
85
+ [ this . npm . flatOptions . cache ] ,
86
+ ] ,
84
87
// TODO:
85
88
// - ensure arborist.loadActual() runs without errors and no invalid edges
86
89
// - ensure package-lock.json matches loadActual()
@@ -202,11 +205,7 @@ class Doctor extends BaseCommand {
202
205
}
203
206
}
204
207
205
- async checkFilesPermission ( root , shouldOwn , mask = null ) {
206
- if ( mask === null ) {
207
- mask = shouldOwn ? R_OK | W_OK : R_OK
208
- }
209
-
208
+ async checkFilesPermission ( root , shouldOwn , mask , missingOk ) {
210
209
let ok = true
211
210
212
211
const tracker = log . newItem ( root , 1 )
@@ -218,8 +217,11 @@ class Doctor extends BaseCommand {
218
217
for ( const f of files ) {
219
218
tracker . silly ( 'checkFilesPermission' , f . substr ( root . length + 1 ) )
220
219
const st = await lstat ( f ) . catch ( er => {
221
- ok = false
222
- tracker . warn ( 'checkFilesPermission' , 'error getting info for ' + f )
220
+ // if it can't be missing, or if it can and the error wasn't that it was missing
221
+ if ( ! missingOk || er . code !== 'ENOENT' ) {
222
+ ok = false
223
+ tracker . warn ( 'checkFilesPermission' , 'error getting info for ' + f )
224
+ }
223
225
} )
224
226
225
227
tracker . completeWork ( 1 )
0 commit comments