3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
- import * as fs from 'fs-extra'
6
+ import { promises as fsPromises } from 'fs'
7
+ import fs from 'fs'
7
8
import * as vscode from 'vscode'
8
9
import * as os from 'os'
9
10
import * as path from 'path'
@@ -28,7 +29,7 @@ export function createPermissionsErrorHandler(
28
29
}
29
30
30
31
const userInfo = os . userInfo ( { encoding : 'utf-8' } )
31
- const stats = await fs . stat ( uri . fsPath ) . catch ( async err2 => {
32
+ const stats = await fsPromises . stat ( uri . fsPath ) . catch ( async err2 => {
32
33
if ( ! isNoPermissionsError ( err2 ) && ! ( isFileNotFoundError ( err2 ) && perms [ 1 ] === 'w' ) ) {
33
34
throw err
34
35
}
@@ -70,7 +71,7 @@ export class SystemUtilities {
70
71
const errorHandler = createPermissionsErrorHandler ( uri , 'r**' )
71
72
72
73
if ( isCloud9 ( ) ) {
73
- return decoder . decode ( await fs . readFile ( uri . fsPath ) . catch ( errorHandler ) )
74
+ return decoder . decode ( await fsPromises . readFile ( uri . fsPath ) . catch ( errorHandler ) )
74
75
}
75
76
76
77
return decoder . decode ( await vscode . workspace . fs . readFile ( uri ) . then ( undefined , errorHandler ) )
@@ -86,7 +87,7 @@ export class SystemUtilities {
86
87
const content = typeof data === 'string' ? new TextEncoder ( ) . encode ( data ) : data
87
88
88
89
if ( isCloud9 ( ) ) {
89
- return fs . writeFile ( uri . fsPath , content , opt ) . catch ( errorHandler )
90
+ return fsPromises . writeFile ( uri . fsPath , content , opt ) . catch ( errorHandler )
90
91
}
91
92
92
93
return vscode . workspace . fs . writeFile ( uri , content ) . then ( undefined , errorHandler )
@@ -98,11 +99,11 @@ export class SystemUtilities {
98
99
const errorHandler = createPermissionsErrorHandler ( dirUri , '*wx' )
99
100
100
101
if ( isCloud9 ( ) ) {
101
- const stat = await fs . stat ( uri . fsPath )
102
+ const stat = await fsPromises . stat ( uri . fsPath )
102
103
if ( stat . isDirectory ( ) ) {
103
- return fs . remove ( uri . fsPath ) . catch ( errorHandler )
104
+ return fsPromises . rmdir ( uri . fsPath ) . catch ( errorHandler )
104
105
} else {
105
- return fs . unlink ( uri . fsPath ) . catch ( errorHandler )
106
+ return fsPromises . unlink ( uri . fsPath ) . catch ( errorHandler )
106
107
}
107
108
}
108
109
@@ -120,7 +121,7 @@ export class SystemUtilities {
120
121
} else if ( uri . scheme !== 'file' || ! isFileNotFoundError ( err ) || process . platform === 'win32' ) {
121
122
throw err
122
123
} else {
123
- const stats = await fs . stat ( dirUri . fsPath ) . catch ( ( ) => {
124
+ const stats = await fsPromises . stat ( dirUri . fsPath ) . catch ( ( ) => {
124
125
throw err
125
126
} )
126
127
if ( ( stats . mode & fs . constants . S_IXUSR ) === 0 ) {
@@ -138,7 +139,10 @@ export class SystemUtilities {
138
139
const uri = typeof file === 'string' ? vscode . Uri . file ( file ) : file
139
140
140
141
if ( isCloud9 ( ) ) {
141
- return new Promise < boolean > ( resolve => fs . access ( uri . fsPath , fs . constants . F_OK , err => resolve ( ! err ) ) )
142
+ return fsPromises . access ( uri . fsPath , fs . constants . F_OK ) . then (
143
+ ( ) => true ,
144
+ ( ) => false
145
+ )
142
146
}
143
147
144
148
return vscode . workspace . fs . stat ( uri ) . then (
@@ -152,7 +156,10 @@ export class SystemUtilities {
152
156
const errorHandler = createPermissionsErrorHandler ( vscode . Uri . joinPath ( uri , '..' ) , '*wx' )
153
157
154
158
if ( isCloud9 ( ) ) {
155
- return fs . ensureDir ( uri . fsPath ) . catch ( errorHandler )
159
+ return fsPromises
160
+ . mkdir ( uri . fsPath , { recursive : true } )
161
+ . then ( ( ) => { } )
162
+ . catch ( errorHandler )
156
163
}
157
164
158
165
return vscode . workspace . fs . createDirectory ( uri ) . then ( undefined , errorHandler )
@@ -170,13 +177,13 @@ export class SystemUtilities {
170
177
*
171
178
* This throws {@link PermissionsError} when permissions are insufficient.
172
179
*/
173
- public static async checkPerms ( file : string | vscode . Uri , perms : PermissionsTriplet ) {
180
+ public static async checkPerms ( file : string | vscode . Uri , perms : PermissionsTriplet ) : Promise < void > {
174
181
const uri = typeof file === 'string' ? vscode . Uri . file ( file ) : file
175
182
const errorHandler = createPermissionsErrorHandler ( uri , perms )
176
183
const flags = Array . from ( perms ) as ( keyof typeof this . modeMap ) [ ]
177
184
const mode = flags . reduce ( ( m , f ) => m | this . modeMap [ f ] , fs . constants . F_OK )
178
185
179
- return fs . access ( uri . fsPath , mode ) . catch ( errorHandler )
186
+ return fsPromises . access ( uri . fsPath , mode ) . catch ( errorHandler )
180
187
}
181
188
182
189
// TODO: implement this by checking the file mode
@@ -242,7 +249,7 @@ export class SystemUtilities {
242
249
'code' , // $PATH
243
250
]
244
251
for ( const vsc of vscs ) {
245
- if ( ! vsc || ( vsc !== 'code' && ! fs . existsSync ( vsc ) ) ) {
252
+ if ( ! vsc || ( vsc !== 'code' && ! ( await this . fileExists ( vsc ) ) ) ) {
246
253
continue
247
254
}
248
255
if ( await SystemUtilities . tryRun ( vsc , [ '--version' ] ) ) {
@@ -296,7 +303,7 @@ export class SystemUtilities {
296
303
'C:/Program Files/Git/usr/bin/ssh.exe' ,
297
304
]
298
305
for ( const p of paths ) {
299
- if ( ! p || ( 'ssh' !== p && ! fs . existsSync ( p ) ) ) {
306
+ if ( ! p || ( 'ssh' !== p && ! ( await this . fileExists ( p ) ) ) ) {
300
307
continue
301
308
}
302
309
if ( await SystemUtilities . tryRun ( p , [ '-G' , 'x' ] , 'noresult' /* "ssh -G" prints quasi-sensitive info. */ ) ) {
@@ -318,7 +325,7 @@ export class SystemUtilities {
318
325
319
326
const paths = [ git . gitPath , 'git' ]
320
327
for ( const p of paths ) {
321
- if ( ! p || ( 'git' !== p && ! fs . existsSync ( p ) ) ) {
328
+ if ( ! p || ( 'git' !== p && ! ( await this . fileExists ( p ) ) ) ) {
322
329
continue
323
330
}
324
331
if ( await SystemUtilities . tryRun ( p , [ '--version' ] ) ) {
@@ -338,7 +345,7 @@ export class SystemUtilities {
338
345
339
346
const paths = [ 'bash' , 'C:/Program Files/Git/usr/bin/bash.exe' , 'C:/Program Files (x86)/Git/usr/bin/bash.exe' ]
340
347
for ( const p of paths ) {
341
- if ( ! p || ( 'bash' !== p && ! fs . existsSync ( p ) ) ) {
348
+ if ( ! p || ( 'bash' !== p && ! ( await this . fileExists ( p ) ) ) ) {
342
349
continue
343
350
}
344
351
if ( await SystemUtilities . tryRun ( p , [ '--version' ] ) ) {
0 commit comments