@@ -248,9 +248,19 @@ export class DefaultReporter implements Reporter {
248248 ctx . log ( `Plugin: "${ pluginName } " requires root access to run command: "sudo ${ data . command } "` ) ;
249249 const title = `Plugin: "${ pluginName } " requires root access to run command: "sudo ${ data . command } "` ;
250250
251- const password = await this . promptSudoPassword ( { title, cancellable : false } ) ;
251+ // Saving is only offered when a cache is registered (i.e. not in secure mode)
252+ const savable = this . sudoPasswordSubmittedCallback !== null ;
253+ const result = await this . promptSudoPassword ( { title, cancellable : false , savable } ) ;
254+
255+ if ( result ?. save ) {
256+ const isValid = await this . sudoPasswordSubmittedCallback ! ( result . password ) ;
257+ if ( isValid ) {
258+ store . set ( store . isSudoPasswordCached , true ) ;
259+ }
260+ }
261+
252262 await this . displayProgress ( ) ;
253- return password ;
263+ return result ?. password ;
254264 }
255265
256266 async displayPlan ( plan : Plan ) : Promise < void > {
@@ -380,10 +390,10 @@ export class DefaultReporter implements Reporter {
380390
381391 private async handleInlineSudoPassword ( ) : Promise < void > {
382392 ctx . log ( 'Prompting sudo to save password for rest of requests' ) ;
383- const password = await this . promptSudoPassword ( { cancellable : true } ) ;
393+ const result = await this . promptSudoPassword ( { cancellable : true , savable : false } ) ;
384394
385- if ( password != null ) {
386- const isValid = await ( this . sudoPasswordSubmittedCallback ?.( password ) ?? Promise . resolve ( false ) ) ;
395+ if ( result != null ) {
396+ const isValid = await ( this . sudoPasswordSubmittedCallback ?.( result . password ) ?? Promise . resolve ( false ) ) ;
387397 if ( isValid ) {
388398 store . set ( store . isSudoPasswordCached , true ) ;
389399 }
@@ -393,35 +403,38 @@ export class DefaultReporter implements Reporter {
393403 }
394404
395405 // Shared prompt loop for both inline (cancellable) and blocking (non-cancellable) sudo password entry.
396- // Returns the validated password, or undefined if the user cancelled (only possible when cancellable=true).
397- private async promptSudoPassword ( opts : { title ?: string ; cancellable : boolean } ) : Promise < string | undefined > {
398- const { title, cancellable } = opts ;
406+ // Returns the validated password and whether the user chose to save it, or undefined if the user cancelled
407+ // (only possible when cancellable=true).
408+ private async promptSudoPassword (
409+ opts : { title ?: string ; cancellable : boolean ; savable : boolean }
410+ ) : Promise < { password : string ; save : boolean } | undefined > {
411+ const { title, cancellable, savable } = opts ;
399412 let hasError = false ;
400413 let attemptCount = 0 ;
401414
402415 while ( true ) {
403416 attemptCount ++ ;
404417 const result = ( await Promise . all ( [
405- this . updateRenderState ( RenderStatus . SUDO_PROMPT , { attemptCount, hasError, cancellable, title } ) ,
418+ this . updateRenderState ( RenderStatus . SUDO_PROMPT , { attemptCount, hasError, cancellable, savable , title } ) ,
406419 Promise . race ( [
407- this . awaitEvent < string > ( RenderEvent . SUDO_PROMPT_RESULT ) ,
420+ this . awaitEvent < { password : string ; save : boolean } > ( RenderEvent . SUDO_PROMPT_RESULT ) ,
408421 ...( cancellable
409422 ? [ this . awaitEvent < 'cancel' > ( RenderEvent . SUDO_PASSWORD_CANCEL ) . then ( ( ) => Symbol . for ( 'cancel' ) ) ]
410423 : [ ] ) ,
411424 ] ) ,
412- ] ) ) . at ( 1 ) as string | symbol ;
425+ ] ) ) . at ( 1 ) as { password : string ; save : boolean } | symbol ;
413426
414427 if ( result === Symbol . for ( 'cancel' ) ) {
415428 return undefined ;
416429 }
417430
418- const password = result as string ;
431+ const { password, save } = result as { password : string ; save : boolean } ;
419432 const isValid = await SudoUtils . validate ( password ) ;
420433
421434 if ( isValid ) {
422435 ctx . log ( 'Sudo password successful!' ) ;
423436 await SudoUtils . invalidate ( ) ;
424- return password ;
437+ return { password, save } ;
425438 }
426439
427440 hasError = true ;
0 commit comments