@@ -2,7 +2,7 @@ import * as path from "path";
22import * as vscode from "vscode" ;
33import { isText } from "istextorbinary" ;
44import { AtelierAPI } from "../../api" ;
5- import { fireOtherStudioAction , OtherStudioAction , StudioActions } from "../../commands/studio" ;
5+ import { fireOtherStudioAction , OtherStudioAction } from "../../commands/studio" ;
66import { isfsConfig , projectContentsFromUri , studioOpenDialogFromURI } from "../../utils/FileProviderUtil" ;
77import {
88 classNameRegex ,
@@ -234,6 +234,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
234234 }
235235
236236 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+ }
237240 let entryPromise : Promise < Entry > ;
238241 let result : Entry ;
239242 const redirectedUri = redirectDotvscodeRoot ( uri ) ;
@@ -284,19 +287,14 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
284287 }
285288
286289 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+ }
288293 const parent = await this . _lookupAsDirectory ( uri ) ;
289294 const api = new AtelierAPI ( uri ) ;
290295 if ( ! api . active ) throw vscode . FileSystemError . Unavailable ( uri ) ;
291296 const { csp, project } = isfsConfig ( uri ) ;
292297 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-
300298 // Get all items in the project
301299 return projectContentsFromUri ( uri ) . then ( ( entries ) =>
302300 entries . map ( ( entry ) => {
@@ -405,7 +403,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
405403 }
406404
407405 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+ }
409409 const basename = path . posix . basename ( uri . path ) ;
410410 const dirname = uri . with ( { path : path . posix . dirname ( uri . path ) } ) ;
411411 return this . _lookupAsDirectory ( dirname ) . then ( ( parent ) => {
@@ -421,6 +421,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
421421 }
422422
423423 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+ }
424427 // Use _lookup() instead of _lookupAsFile() so we send
425428 // our cached mtime with the GET /doc request if we have it
426429 return this . _lookup ( uri , true ) . then ( ( file : File ) => {
@@ -439,6 +442,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
439442 overwrite : boolean ;
440443 }
441444 ) : 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+ }
442448 uri = redirectDotvscodeRoot ( uri ) ;
443449 if ( uri . path . startsWith ( "/." ) ) {
444450 throw vscode . FileSystemError . NoPermissions ( "dot-folders not supported by server" ) ;
@@ -606,6 +612,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
606612 }
607613
608614 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+ }
609618 uri = redirectDotvscodeRoot ( uri ) ;
610619 const { project } = isfsConfig ( uri ) ;
611620 const csp = isCSP ( uri ) ;
@@ -699,6 +708,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
699708 if ( vscode . workspace . getWorkspaceFolder ( oldUri ) != vscode . workspace . getWorkspaceFolder ( newUri ) ) {
700709 throw vscode . FileSystemError . NoPermissions ( "Cannot rename a file across workspace folders" ) ;
701710 }
711+ if ( oldUri . path . includes ( ".vscode/" ) || newUri . path . includes ( ".vscode/" ) ) {
712+ throw vscode . FileSystemError . NoPermissions ( "Cannot rename a file in the /.vscode directory" ) ;
713+ }
702714 // Check if the destination exists
703715 let newFileStat : vscode . FileStat ;
704716 try {
@@ -864,11 +876,6 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
864876 // Fetch entry (a file or directory) from cache, else from server
865877 private async _lookup ( uri : vscode . Uri , fillInPath ?: boolean ) : Promise < Entry > {
866878 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- }
872879 const config = api . config ;
873880 const rootName = `${ config . username } @${ config . host } :${ config . port } ${ config . pathPrefix } /${ config . ns . toUpperCase ( ) } ` ;
874881 let entry : Entry = this . superRoot . entries . get ( rootName ) ;
0 commit comments