Subject: bug#76323: 30.0.93; auth-source-pass: Annoying error when ~/.password-store doesn't exist

From: "Basil L. Contovounesios" <[email-masked]>
Date: Sun, 16 Feb 2025 17:47:14 +0100

Naofumi Yasufuku [2025-02-16 22:57 +0900] wrote:

> I noticed that auth-source-pass-entries is called many times
> for each search pattern

Ouch!

> I think it would be better to have just one additional dir check on
> auth-source-pass-search instead of auth-source-pass-entries.
> auth-source-pass backend just does nothing if password-store dir is not
> available.  Could it be relatively reasonable cost?

Sounds even better to me.

[ I can imagine external users of auth-source-pass-entries also
  benefitting from the filesystem guard, but I think we can leave it up
  to them to decide if/when/how they need it. ]

CCing some of the recent auth-source-pass (and ERC) contributors in case
they have any comments on the patch below.

[ The original attachment and the rest of the discussion can be found
  here: https://bugs.gnu.org/76323#11 ]

If there are no objections, I think this can be applied soon.

Yasufuku-san, do you have a copyright assignment to the FSF?
I think this contribution is still well within the limits for being
exempt, but for future contributions perhaps you would be interested in
starting the process now, if you haven't already?

> From c42a3abeb04b7c28f8532497fe9c9f0e50521a27 Mon Sep 17 00:00:00 2001
> From: Naofumi Yasufuku <[email-masked]>
> Date: Sun, 16 Feb 2025 21:12:17 +0900
> Subject: [PATCH] auth-source-pass: Don't raise errors if ~/.password-store
>  doesn't exist
>
> * lisp/auth-source-pass.el (auth-source-pass-search):
> If auth-source-pass-filename is not a directory, just do nothing to
> avoid repeated errors raised by directory-files-recursively in
> auth-source-pass-entries which is called for each search pattern.
> (Bug#76323)
> ---
>  lisp/auth-source-pass.el | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el
> index 80ddb38fa88..33786a14a87 100644
> --- a/lisp/auth-source-pass.el
> +++ b/lisp/auth-source-pass.el
> @@ -85,6 +85,9 @@ auth-source-pass-search
>          ((null host)
>           ;; Do not build a result, as none will match when HOST is nil
>           nil)
> +        ((not (file-directory-p (expand-file-name auth-source-pass-filename)))
> +         ;; Do nothing if the password-store folder doesn't exist.
> +         nil)
>          (auth-source-pass-extra-query-keywords
>           (auth-source-pass--build-result-many host port user require max))
>          (t

Thanks,
-- 
Basil