On Mon Jun 26, 2023 at 2:43 PM CST, Armin Preiml wrote:
> > @@ -190,10 +190,11 @@ fn exec_query(serv: *server, client: *client, args: []str) (void | cmderror) = {
> > writefmt(client, "error Failed to unlock");
> > return;
> > };
> > - if (!decrypt) {
> > + if (decrypt) {
> > + prompter = new;
> > + } else {
> > prompt::close(&new)?;
> > };
> > - prompter = new;
> > };
> >
> > const q = query::parse_items(cmd.args)?;
> > @@ -236,6 +237,8 @@ fn exec_query(serv: *server, client: *client, args: []str) (void | cmderror) = {
> > writefmt(client, "error User declined");
> > return;
> > };
> > + } else if (prompter is prompt::prompter) {
> > + prompt::close(&(prompter: prompt::prompter))?;
> > };
>
> It would be safer to use a defer after defining prompter like:
>
> defer if (prompter is prompt::prompter) promt::close...
>
> This would make the code a little less complex.
The challenge here is that prompt::wait also closes the prompter, so if
the prompter is created for unlocking and futher reused for decrypting,
the prompter would be already closed by prompt::wait.
We can add a check in defer for that case, but I think it will be more
complex instead than this patch.
On 6/26/23 10:36, Pinghao Wu wrote:
>>> const q = query::parse_items(cmd.args)?;
>>> @@ -236,6 +237,8 @@ fn exec_query(serv: *server, client: *client, args: []str) (void | cmderror) = {
>>> writefmt(client, "error User declined");
>>> return;
>>> };
>>> + } else if (prompter is prompt::prompter) {
>>> + prompt::close(&(prompter: prompt::prompter))?;
>>> };
>>
>> It would be safer to use a defer after defining prompter like:
>>
>> defer if (prompter is prompt::prompter) promt::close...
>>
>> This would make the code a little less complex.
>
> The challenge here is that prompt::wait also closes the prompter, so if
> the prompter is created for unlocking and futher reused for decrypting,
> the prompter would be already closed by prompt::wait.
>
> We can add a check in defer for that case, but I think it will be more
> complex instead than this patch.
What about setting prompt to void after wait?