@@ -23,6 +23,7 @@ import crypto from 'crypto'
23
23
import { waitUntil } from '../utilities/timeoutUtils'
24
24
import { telemetry } from '../telemetry/telemetry'
25
25
import { getLogger } from '../logger/logger'
26
+ import { toUri } from '../utilities/uriUtils'
26
27
27
28
const vfs = vscode . workspace . fs
28
29
type Uri = vscode . Uri
@@ -88,7 +89,7 @@ export class FileSystem {
88
89
89
90
/** Creates the directory as well as missing parent directories. */
90
91
async mkdir ( path : Uri | string ) : Promise < void > {
91
- const uri = this . # toUri( path )
92
+ const uri = toUri ( path )
92
93
const errHandler = createPermissionsErrorHandler ( this . isWeb , vscode . Uri . joinPath ( uri , '..' ) , '*wx' )
93
94
94
95
// Certain URIs are not supported with vscode.workspace.fs in Cloud9
@@ -105,7 +106,7 @@ export class FileSystem {
105
106
106
107
// TODO: rename to readFileBytes()?
107
108
async readFile ( path : Uri | string ) : Promise < Uint8Array > {
108
- const uri = this . # toUri( path )
109
+ const uri = toUri ( path )
109
110
const errHandler = createPermissionsErrorHandler ( this . isWeb , uri , 'r**' )
110
111
111
112
if ( isCloud9 ( ) ) {
@@ -117,7 +118,7 @@ export class FileSystem {
117
118
118
119
// TODO: rename to readFile()?
119
120
async readFileAsString ( path : Uri | string , decoder : TextDecoder = FileSystem . #decoder) : Promise < string > {
120
- const uri = this . # toUri( path )
121
+ const uri = toUri ( path )
121
122
const bytes = await this . readFile ( uri )
122
123
return decoder . decode ( bytes )
123
124
}
@@ -127,7 +128,7 @@ export class FileSystem {
127
128
* so we must do it ourselves (this implementation is inefficient).
128
129
*/
129
130
async appendFile ( path : Uri | string , content : Uint8Array | string ) : Promise < void > {
130
- path = this . # toUri( path )
131
+ path = toUri ( path )
131
132
132
133
const currentContent : Uint8Array = ( await this . existsFile ( path ) ) ? await this . readFile ( path ) : new Uint8Array ( 0 )
133
134
const currentLength = currentContent . length
@@ -146,7 +147,7 @@ export class FileSystem {
146
147
if ( path === undefined || path === '' ) {
147
148
return false
148
149
}
149
- const uri = this . # toUri( path )
150
+ const uri = toUri ( path )
150
151
if ( uri . fsPath === undefined || uri . fsPath === '' ) {
151
152
return false
152
153
}
@@ -212,7 +213,7 @@ export class FileSystem {
212
213
data : string | Uint8Array ,
213
214
opts ?: WriteFileOptions & { atomic ?: boolean }
214
215
) : Promise < void > {
215
- const uri = this . # toUri( path )
216
+ const uri = toUri ( path )
216
217
const errHandler = createPermissionsErrorHandler ( this . isWeb , uri , '*w*' )
217
218
const content = this . #toBytes( data )
218
219
@@ -249,7 +250,7 @@ export class FileSystem {
249
250
// 3. Finally, do a regular file write, but may result in invalid file content
250
251
//
251
252
// For telemetry, we will only report failures as to not overload with succeed events.
252
- const tempFile = this . # toUri( `${ uri . fsPath } .${ crypto . randomBytes ( 8 ) . toString ( 'hex' ) } .tmp` )
253
+ const tempFile = toUri ( `${ uri . fsPath } .${ crypto . randomBytes ( 8 ) . toString ( 'hex' ) } .tmp` )
253
254
try {
254
255
await write ( tempFile )
255
256
await fs . rename ( tempFile , uri )
@@ -290,8 +291,8 @@ export class FileSystem {
290
291
}
291
292
292
293
async rename ( oldPath : vscode . Uri | string , newPath : vscode . Uri | string ) {
293
- const oldUri = this . # toUri( oldPath )
294
- const newUri = this . # toUri( newPath )
294
+ const oldUri = toUri ( oldPath )
295
+ const newUri = toUri ( newPath )
295
296
const errHandler = createPermissionsErrorHandler ( this . isWeb , oldUri , 'rw*' )
296
297
297
298
if ( isCloud9 ( ) ) {
@@ -352,7 +353,7 @@ export class FileSystem {
352
353
* The stat of the file, throws if the file does not exist or on any other error.
353
354
*/
354
355
async stat ( uri : vscode . Uri | string ) : Promise < vscode . FileStat > {
355
- const path = this . # toUri( uri )
356
+ const path = toUri ( uri )
356
357
return await vfs . stat ( path )
357
358
}
358
359
@@ -370,7 +371,7 @@ export class FileSystem {
370
371
async delete ( fileOrDir : string | vscode . Uri , opt_ ?: { recursive ?: boolean ; force ?: boolean } ) : Promise < void > {
371
372
const opt = { ...opt_ , recursive : ! ! opt_ ?. recursive }
372
373
opt . force = opt . force === false ? opt . force : ! ! ( opt . force || opt . recursive )
373
- const uri = this . # toUri( fileOrDir )
374
+ const uri = toUri ( fileOrDir )
374
375
const parent = vscode . Uri . joinPath ( uri , '..' )
375
376
const errHandler = createPermissionsErrorHandler ( this . isWeb , parent , '*wx' )
376
377
@@ -427,7 +428,7 @@ export class FileSystem {
427
428
}
428
429
429
430
async readdir ( uri : vscode . Uri | string ) : Promise < [ string , vscode . FileType ] [ ] > {
430
- const path = this . # toUri( uri )
431
+ const path = toUri ( uri )
431
432
432
433
// readdir is not a supported vscode API in Cloud9
433
434
if ( isCloud9 ( ) ) {
@@ -441,8 +442,8 @@ export class FileSystem {
441
442
}
442
443
443
444
async copy ( source : vscode . Uri | string , target : vscode . Uri | string ) : Promise < void > {
444
- const sourcePath = this . # toUri( source )
445
- const targetPath = this . # toUri( target )
445
+ const sourcePath = toUri ( source )
446
+ const targetPath = toUri ( target )
446
447
return await vfs . copy ( sourcePath , targetPath , { overwrite : true } )
447
448
}
448
449
@@ -454,7 +455,7 @@ export class FileSystem {
454
455
async checkPerms ( file : string | vscode . Uri , perms : PermissionsTriplet ) : Promise < void > {
455
456
// TODO: implement checkExactPerms() by checking the file mode.
456
457
// public static async checkExactPerms(file: string | vscode.Uri, perms: `${PermissionsTriplet}${PermissionsTriplet}${PermissionsTriplet}`)
457
- const uri = this . # toUri( file )
458
+ const uri = toUri ( file )
458
459
const errHandler = createPermissionsErrorHandler ( this . isWeb , uri , perms )
459
460
const flags = Array . from ( perms ) as ( keyof typeof this . modeMap ) [ ]
460
461
const mode = flags . reduce ( ( m , f ) => m | this . modeMap [ f ] , nodeConstants . F_OK )
@@ -634,19 +635,6 @@ export class FileSystem {
634
635
return data
635
636
}
636
637
637
- /**
638
- * Retrieve the Uri of the file.
639
- *
640
- * @param path The file path for which to retrieve metadata.
641
- * @return The Uri about the file.
642
- */
643
- #toUri( path : string | vscode . Uri ) : vscode . Uri {
644
- if ( path instanceof vscode . Uri ) {
645
- return path
646
- }
647
- return vscode . Uri . file ( path )
648
- }
649
-
650
638
private get modeMap ( ) {
651
639
return {
652
640
'*' : 0 ,
0 commit comments