Subject: 28.0.50; `find-file-noselect' + `file-truename' gotcha

From: Michael Heerdegen <[email-masked]>
Date: Wed, 20 May 2020 02:34:43 +0200

Hello,

`find-file-noselect' tries to reuse buffers already visiting the file
under a different name, e.g. via a symlink, but it doesn't check if that
name is still valid (which is not the case when the symlink has been
deleted after the file has been visited using this name).  The behavior
makes it hard to visit the file under its valid name because Emacs
tries to revert the existing buffer which fails.

Here is a recipe, I start with a directory like this:

  /home/micha/Treasure/today/test:
  total used in directory 29 available 123.8 GiB
  drwxrwxr-x  2 micha micha     4k 05-20 02:20 .
  drwxr-xr-x 69 micha micha    24k 05-20 02:19 ..
  -rw-rw-r--  1 micha micha      5 05-20 02:20 a
S lrwxrwxrwx  1 micha micha      1 05-20 02:21 b -> a

I visit b (I did that from dired), then, without killing the b visiting
buffer, I delete the b -> a symlink, then I try to visit "a" and get:

Debugger entered--Lisp error: (error "File /home/micha/today/test/b no longer exists!")
  signal(error ("File /home/micha/today/test/b no longer exists!"))
  error("File %s no longer exists!" "/home/micha/today/test/b")
  revert-buffer-insert-file-contents--default-function("/home/micha/today/test/b" nil)
  revert-buffer--default(t t)
  revert-buffer(t t)
  find-file-noselect("/home/micha/today/test/a")
  view-file("/home/micha/today/test/a")
  dired-view-file()
  funcall-interactively(dired-view-file)
  call-interactively(dired-view-file nil nil)
  command-execute(dired-view-file)

Depending on `revert-without-query' you are asked whether to revert the
"b" buffer.  That will fail.  That "b" buffer should better be ignored
by Emacs to avoid confusion.

Thanks,

Michael.