Subject: Re: bug#41489: `package-dir-info' fails on a directory with a non-saved file

From: Paul Pogonyshev <[email-masked]>
Date: Tue, 26 May 2020 00:55:05 +0200

I also noticed that the error depends on the Moon phase, i.e. it is not
_always_ reproducible. The reason is that it depends on the random order of
elements in `(directory-files default-directory t "\\.el\\'" t)' result.

On Sat, 23 May 2020 at 20:37, Paul Pogonyshev <[email-masked]> wrote:

> Sorry. In any Emacs version. I tested with a fairly recently compiled
> `master', but judging by the source code I checked out two minutes ago, the
> bug is there currently too. The cause is this:
>
>             (insert-file-contents (pop files))
>
> This form is not inside `(ignore-errors ...)' and so any failure is
> propagated out of `package-dir-info' too.
>
> Paul
>
> On Sat, 23 May 2020 at 20:23, Eli Zaretskii <[email-masked]> wrote:
>
>> > From: Paul Pogonyshev <[email-masked]>
>> > Date: Sat, 23 May 2020 19:50:02 +0200
>> >
>> > - edit any Elisp file, but don't save it;
>> > - open its directory in Dired;
>> > - evaluate `(package-dir-info)'.
>> >
>> > Fails with: (file-missing "Opening input file" "No such file or
>> directory" ".../.#blabla.el")
>>
>> In what version of Emacs is that?  Please always supply the
>> information collected by report-emacs-bug, as that saves unnecessary
>> questions such as this one.
>>
>> Thanks.
>>
>>
From 5fd331e43e18e7b0fc11e93eb3b5fcd43a301d36 Mon Sep 17 00:00:00 2001
From: Paul Pogonyshev <[email-masked]>
Date: Tue, 26 May 2020 00:52:14 +0200
Subject: [PATCH] Fix random errors in `package-dir-info' caused by unreadable
 files (bug#39722)

---
 lisp/emacs-lisp/package.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 9a6d1d7319..99ba5d7107 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -1181,7 +1181,9 @@ package-dir-info
             info)
         (while files
           (with-temp-buffer
-            (insert-file-contents (pop files))
+            ;; Skip unreadable files, e.g. locks for unsaved `.el'
+            ;; buffers (bug#41489).
+            (ignore-errors (insert-file-contents (pop files)))
             ;; When we find the file with the data,
             (when (setq info (ignore-errors (package-buffer-info)))
               ;; stop looping,
-- 
2.20.1