@@ -23,6 +23,7 @@ import crypto from 'crypto'
2323import { waitUntil } from '../utilities/timeoutUtils'
2424import { telemetry } from '../telemetry/telemetry'
2525import { getLogger } from '../logger/logger'
26+ import { toUri } from '../utilities/uriUtils'
2627
2728const vfs = vscode . workspace . fs
2829type Uri = vscode . Uri
@@ -88,7 +89,7 @@ export class FileSystem {
8889
8990 /** Creates the directory as well as missing parent directories. */
9091 async mkdir ( path : Uri | string ) : Promise < void > {
91- const uri = this . # toUri( path )
92+ const uri = toUri ( path )
9293 const errHandler = createPermissionsErrorHandler ( this . isWeb , vscode . Uri . joinPath ( uri , '..' ) , '*wx' )
9394
9495 // Certain URIs are not supported with vscode.workspace.fs in Cloud9
@@ -105,7 +106,7 @@ export class FileSystem {
105106
106107 // TODO: rename to readFileBytes()?
107108 async readFile ( path : Uri | string ) : Promise < Uint8Array > {
108- const uri = this . # toUri( path )
109+ const uri = toUri ( path )
109110 const errHandler = createPermissionsErrorHandler ( this . isWeb , uri , 'r**' )
110111
111112 if ( isCloud9 ( ) ) {
@@ -117,7 +118,7 @@ export class FileSystem {
117118
118119 // TODO: rename to readFile()?
119120 async readFileAsString ( path : Uri | string , decoder : TextDecoder = FileSystem . #decoder) : Promise < string > {
120- const uri = this . # toUri( path )
121+ const uri = toUri ( path )
121122 const bytes = await this . readFile ( uri )
122123 return decoder . decode ( bytes )
123124 }
@@ -127,7 +128,7 @@ export class FileSystem {
127128 * so we must do it ourselves (this implementation is inefficient).
128129 */
129130 async appendFile ( path : Uri | string , content : Uint8Array | string ) : Promise < void > {
130- path = this . # toUri( path )
131+ path = toUri ( path )
131132
132133 const currentContent : Uint8Array = ( await this . existsFile ( path ) ) ? await this . readFile ( path ) : new Uint8Array ( 0 )
133134 const currentLength = currentContent . length
@@ -146,7 +147,7 @@ export class FileSystem {
146147 if ( path === undefined || path === '' ) {
147148 return false
148149 }
149- const uri = this . # toUri( path )
150+ const uri = toUri ( path )
150151 if ( uri . fsPath === undefined || uri . fsPath === '' ) {
151152 return false
152153 }
@@ -212,7 +213,7 @@ export class FileSystem {
212213 data : string | Uint8Array ,
213214 opts ?: WriteFileOptions & { atomic ?: boolean }
214215 ) : Promise < void > {
215- const uri = this . # toUri( path )
216+ const uri = toUri ( path )
216217 const errHandler = createPermissionsErrorHandler ( this . isWeb , uri , '*w*' )
217218 const content = this . #toBytes( data )
218219
@@ -249,7 +250,7 @@ export class FileSystem {
249250 // 3. Finally, do a regular file write, but may result in invalid file content
250251 //
251252 // 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` )
253254 try {
254255 await write ( tempFile )
255256 await fs . rename ( tempFile , uri )
@@ -290,8 +291,8 @@ export class FileSystem {
290291 }
291292
292293 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 )
295296 const errHandler = createPermissionsErrorHandler ( this . isWeb , oldUri , 'rw*' )
296297
297298 if ( isCloud9 ( ) ) {
@@ -352,7 +353,7 @@ export class FileSystem {
352353 * The stat of the file, throws if the file does not exist or on any other error.
353354 */
354355 async stat ( uri : vscode . Uri | string ) : Promise < vscode . FileStat > {
355- const path = this . # toUri( uri )
356+ const path = toUri ( uri )
356357 return await vfs . stat ( path )
357358 }
358359
@@ -370,7 +371,7 @@ export class FileSystem {
370371 async delete ( fileOrDir : string | vscode . Uri , opt_ ?: { recursive ?: boolean ; force ?: boolean } ) : Promise < void > {
371372 const opt = { ...opt_ , recursive : ! ! opt_ ?. recursive }
372373 opt . force = opt . force === false ? opt . force : ! ! ( opt . force || opt . recursive )
373- const uri = this . # toUri( fileOrDir )
374+ const uri = toUri ( fileOrDir )
374375 const parent = vscode . Uri . joinPath ( uri , '..' )
375376 const errHandler = createPermissionsErrorHandler ( this . isWeb , parent , '*wx' )
376377
@@ -427,7 +428,7 @@ export class FileSystem {
427428 }
428429
429430 async readdir ( uri : vscode . Uri | string ) : Promise < [ string , vscode . FileType ] [ ] > {
430- const path = this . # toUri( uri )
431+ const path = toUri ( uri )
431432
432433 // readdir is not a supported vscode API in Cloud9
433434 if ( isCloud9 ( ) ) {
@@ -441,8 +442,8 @@ export class FileSystem {
441442 }
442443
443444 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 )
446447 return await vfs . copy ( sourcePath , targetPath , { overwrite : true } )
447448 }
448449
@@ -454,7 +455,7 @@ export class FileSystem {
454455 async checkPerms ( file : string | vscode . Uri , perms : PermissionsTriplet ) : Promise < void > {
455456 // TODO: implement checkExactPerms() by checking the file mode.
456457 // public static async checkExactPerms(file: string | vscode.Uri, perms: `${PermissionsTriplet}${PermissionsTriplet}${PermissionsTriplet}`)
457- const uri = this . # toUri( file )
458+ const uri = toUri ( file )
458459 const errHandler = createPermissionsErrorHandler ( this . isWeb , uri , perms )
459460 const flags = Array . from ( perms ) as ( keyof typeof this . modeMap ) [ ]
460461 const mode = flags . reduce ( ( m , f ) => m | this . modeMap [ f ] , nodeConstants . F_OK )
@@ -634,19 +635,6 @@ export class FileSystem {
634635 return data
635636 }
636637
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-
650638 private get modeMap ( ) {
651639 return {
652640 '*' : 0 ,
0 commit comments