@@ -124,6 +124,15 @@ export async function maybePromptForSettings(
124124
125125 const envContent = formatEnvContent ( nonSensitiveSettings ) ;
126126
127+ if ( fsSync . existsSync ( envFilePath ) ) {
128+ const stat = fsSync . statSync ( envFilePath ) ;
129+ if ( stat . isDirectory ( ) ) {
130+ throw new Error (
131+ `Cannot write extension settings to ${ envFilePath } because it is a directory.` ,
132+ ) ;
133+ }
134+ }
135+
127136 await fs . writeFile ( envFilePath , envContent ) ;
128137}
129138
@@ -173,8 +182,11 @@ export async function getScopedEnvContents(
173182 const envFilePath = getEnvFilePath ( extensionName , scope , workspaceDir ) ;
174183 let customEnv : Record < string , string > = { } ;
175184 if ( fsSync . existsSync ( envFilePath ) ) {
176- const envFile = fsSync . readFileSync ( envFilePath , 'utf-8' ) ;
177- customEnv = dotenv . parse ( envFile ) ;
185+ const stat = fsSync . statSync ( envFilePath ) ;
186+ if ( ! stat . isDirectory ( ) ) {
187+ const envFile = fsSync . readFileSync ( envFilePath , 'utf-8' ) ;
188+ customEnv = dotenv . parse ( envFile ) ;
189+ }
178190 }
179191
180192 if ( extensionConfig . settings ) {
@@ -260,6 +272,12 @@ export async function updateSetting(
260272 const envFilePath = getEnvFilePath ( extensionName , scope , workspaceDir ) ;
261273 let envContent = '' ;
262274 if ( fsSync . existsSync ( envFilePath ) ) {
275+ const stat = fsSync . statSync ( envFilePath ) ;
276+ if ( stat . isDirectory ( ) ) {
277+ throw new Error (
278+ `Cannot write extension settings to ${ envFilePath } because it is a directory.` ,
279+ ) ;
280+ }
263281 envContent = await fs . readFile ( envFilePath , 'utf-8' ) ;
264282 }
265283
@@ -324,7 +342,10 @@ async function clearSettings(
324342 keychain : KeychainTokenStorage ,
325343) {
326344 if ( fsSync . existsSync ( envFilePath ) ) {
327- await fs . writeFile ( envFilePath , '' ) ;
345+ const stat = fsSync . statSync ( envFilePath ) ;
346+ if ( ! stat . isDirectory ( ) ) {
347+ await fs . writeFile ( envFilePath , '' ) ;
348+ }
328349 }
329350 if ( ! ( await keychain . isAvailable ( ) ) ) {
330351 return ;
0 commit comments