@@ -143,7 +143,19 @@ export class ConfigServiceImpl
143
143
try {
144
144
const cliConfig = await this . loadCliConfig ( ) ;
145
145
this . cliConfig = cliConfig ;
146
- const config = await this . mapCliConfigToAppConfig ( this . cliConfig ) ;
146
+ const [ config ] = await Promise . all ( [
147
+ this . mapCliConfigToAppConfig ( this . cliConfig ) ,
148
+ this . ensureUserDirExists ( this . cliConfig ) . catch ( ( reason ) => {
149
+ if ( reason instanceof Error ) {
150
+ this . logger . warn (
151
+ `Could not ensure user directory existence: ${ this . cliConfig ?. directories . user } ` ,
152
+ reason
153
+ ) ;
154
+ }
155
+ // NOOP. Try to create the folder if missing but swallow any errors.
156
+ // The validation will take care of the missing location handling.
157
+ } ) ,
158
+ ] ) ;
147
159
this . _configState . config = config ;
148
160
await this . validateCliConfig ( this . cliConfig ) ;
149
161
delete this . _configState . messages ;
@@ -249,7 +261,6 @@ export class ConfigServiceImpl
249
261
private async checkAccessible ( {
250
262
directories,
251
263
} : DefaultCliConfig ) : Promise < string [ ] > {
252
- // Both data and user folders must be read and writable
253
264
const accessible = ( folderPath : string ) =>
254
265
fs . access ( folderPath , constants . R_OK | constants . W_OK ) ;
255
266
const toConfigErrors = (
@@ -268,14 +279,11 @@ export class ConfigServiceImpl
268
279
) ,
269
280
]
270
281
: [ ] ;
271
- const { user, data } = directories ;
272
- const [ userAccessible , dataAccessible ] = await Promise . allSettled ( [
273
- accessible ( user ) ,
274
- accessible ( data ) ,
275
- ] ) ;
276
- return ( [ ] as string [ ] )
277
- . concat ( toConfigErrors ( 'user' , user , userAccessible ) )
278
- . concat ( toConfigErrors ( 'data' , data , dataAccessible ) ) ;
282
+ const { user } = directories ;
283
+ const [ userAccessible ] = await Promise . allSettled ( [ accessible ( user ) ] ) ; // XXX: validate `directory.data` if required
284
+ return ( [ ] as string [ ] ) . concat (
285
+ toConfigErrors ( 'user' , user , userAccessible )
286
+ ) ;
279
287
}
280
288
281
289
private async updateDaemon (
@@ -335,6 +343,13 @@ export class ConfigServiceImpl
335
343
grpc . credentials . createInsecure ( )
336
344
) as SettingsServiceClient ;
337
345
}
346
+
347
+ // #1445
348
+ private async ensureUserDirExists (
349
+ cliConfig : DefaultCliConfig
350
+ ) : Promise < void > {
351
+ await fs . mkdir ( cliConfig . directories . user , { recursive : true } ) ;
352
+ }
338
353
}
339
354
340
355
class InvalidConfigError extends Error {
0 commit comments