@@ -2,7 +2,7 @@ import * as path from "path";
2
2
import * as vscode from "vscode" ;
3
3
import { isText } from "istextorbinary" ;
4
4
import { AtelierAPI } from "../../api" ;
5
- import { fireOtherStudioAction , OtherStudioAction , StudioActions } from "../../commands/studio" ;
5
+ import { fireOtherStudioAction , OtherStudioAction } from "../../commands/studio" ;
6
6
import { isfsConfig , projectContentsFromUri , studioOpenDialogFromURI } from "../../utils/FileProviderUtil" ;
7
7
import {
8
8
classNameRegex ,
@@ -234,6 +234,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
234
234
}
235
235
236
236
public async stat ( uri : vscode . Uri ) : Promise < vscode . FileStat > {
237
+ if ( uri . path . includes ( ".vscode/" ) && ! uri . path . endsWith ( "/settings.json" ) ) {
238
+ throw vscode . FileSystemError . NoPermissions ( "Only settings.json is allowed within the /.vscode directory" ) ;
239
+ }
237
240
let entryPromise : Promise < Entry > ;
238
241
let result : Entry ;
239
242
const redirectedUri = redirectDotvscodeRoot ( uri ) ;
@@ -284,19 +287,14 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
284
287
}
285
288
286
289
public async readDirectory ( uri : vscode . Uri ) : Promise < [ string , vscode . FileType ] [ ] > {
287
- uri = redirectDotvscodeRoot ( uri ) ;
290
+ if ( uri . path . includes ( ".vscode/" ) ) {
291
+ throw vscode . FileSystemError . NoPermissions ( "Cannot read the /.vscode directory" ) ;
292
+ }
288
293
const parent = await this . _lookupAsDirectory ( uri ) ;
289
294
const api = new AtelierAPI ( uri ) ;
290
295
if ( ! api . active ) throw vscode . FileSystemError . Unavailable ( uri ) ;
291
296
const { csp, project } = isfsConfig ( uri ) ;
292
297
if ( project ) {
293
- if ( [ "" , "/" ] . includes ( uri . path ) ) {
294
- // Technically a project is a "document", so tell the server that we're opening it
295
- await new StudioActions ( ) . fireProjectUserAction ( api , project , OtherStudioAction . OpenedDocument ) . catch ( ( ) => {
296
- // Swallow error because showing it is more disruptive than using a potentially outdated project definition
297
- } ) ;
298
- }
299
-
300
298
// Get all items in the project
301
299
return projectContentsFromUri ( uri ) . then ( ( entries ) =>
302
300
entries . map ( ( entry ) => {
@@ -405,7 +403,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
405
403
}
406
404
407
405
public createDirectory ( uri : vscode . Uri ) : void | Thenable < void > {
408
- uri = redirectDotvscodeRoot ( uri ) ;
406
+ if ( uri . path . includes ( ".vscode/" ) ) {
407
+ throw vscode . FileSystemError . NoPermissions ( "Cannot create a subdirectory of the /.vscode directory" ) ;
408
+ }
409
409
const basename = path . posix . basename ( uri . path ) ;
410
410
const dirname = uri . with ( { path : path . posix . dirname ( uri . path ) } ) ;
411
411
return this . _lookupAsDirectory ( dirname ) . then ( ( parent ) => {
@@ -421,6 +421,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
421
421
}
422
422
423
423
public async readFile ( uri : vscode . Uri ) : Promise < Uint8Array > {
424
+ if ( uri . path . includes ( ".vscode/" ) && ! uri . path . endsWith ( "/settings.json" ) ) {
425
+ throw vscode . FileSystemError . NoPermissions ( "Only settings.json is allowed within the /.vscode directory" ) ;
426
+ }
424
427
// Use _lookup() instead of _lookupAsFile() so we send
425
428
// our cached mtime with the GET /doc request if we have it
426
429
return this . _lookup ( uri , true ) . then ( ( file : File ) => {
@@ -439,6 +442,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
439
442
overwrite : boolean ;
440
443
}
441
444
) : void | Thenable < void > {
445
+ if ( uri . path . includes ( ".vscode/" ) && ! uri . path . endsWith ( "/settings.json" ) ) {
446
+ throw vscode . FileSystemError . NoPermissions ( "Only settings.json is allowed within the /.vscode directory" ) ;
447
+ }
442
448
uri = redirectDotvscodeRoot ( uri ) ;
443
449
if ( uri . path . startsWith ( "/." ) ) {
444
450
throw vscode . FileSystemError . NoPermissions ( "dot-folders not supported by server" ) ;
@@ -606,6 +612,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
606
612
}
607
613
608
614
public async delete ( uri : vscode . Uri , options : { recursive : boolean } ) : Promise < void > {
615
+ if ( uri . path . includes ( ".vscode/" ) && ! uri . path . endsWith ( "/settings.json" ) ) {
616
+ throw vscode . FileSystemError . NoPermissions ( "Only settings.json is allowed within the /.vscode directory" ) ;
617
+ }
609
618
uri = redirectDotvscodeRoot ( uri ) ;
610
619
const { project } = isfsConfig ( uri ) ;
611
620
const csp = isCSP ( uri ) ;
@@ -699,6 +708,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
699
708
if ( vscode . workspace . getWorkspaceFolder ( oldUri ) != vscode . workspace . getWorkspaceFolder ( newUri ) ) {
700
709
throw vscode . FileSystemError . NoPermissions ( "Cannot rename a file across workspace folders" ) ;
701
710
}
711
+ if ( oldUri . path . includes ( ".vscode/" ) || newUri . path . includes ( ".vscode/" ) ) {
712
+ throw vscode . FileSystemError . NoPermissions ( "Cannot rename a file in the /.vscode directory" ) ;
713
+ }
702
714
// Check if the destination exists
703
715
let newFileStat : vscode . FileStat ;
704
716
try {
@@ -864,11 +876,6 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
864
876
// Fetch entry (a file or directory) from cache, else from server
865
877
private async _lookup ( uri : vscode . Uri , fillInPath ?: boolean ) : Promise < Entry > {
866
878
const api = new AtelierAPI ( uri ) ;
867
- if ( uri . path === "/" ) {
868
- await api . serverInfo ( ) . catch ( ( error ) => {
869
- throw vscode . FileSystemError . Unavailable ( stringifyError ( error ) || uri ) ;
870
- } ) ;
871
- }
872
879
const config = api . config ;
873
880
const rootName = `${ config . username } @${ config . host } :${ config . port } ${ config . pathPrefix } /${ config . ns . toUpperCase ( ) } ` ;
874
881
let entry : Entry = this . superRoot . entries . get ( rootName ) ;
0 commit comments