Subject: Re: bug#26996: 25.1; doc-view-revert-buffer doesn't detect file change while using tramp

From: Stefan Monnier <[email-masked]>
Date: Fri, 01 Nov 2019 16:07:15 -0400

>> I have problem with reverting buffer when opening pdf via tramp. 
>> This happens in emacs 24 and emacs 25, with different version of tramp. 
>>
>> Steps to reproduce are like this: 
>> 1. Open pdf with tramp over ssh -> DocView mode. 
>> 2. Update the pdf somehow on the server. 
>> 3. Press 'g' to revert buffer (doc-view-revert-buffer) -> "yes". 
>>
>> If the pdf was updated, I expect to see an updated pdf. Instead I see an 
>> old pdf. 
>
> I managed to reproduce this in Emacs 27, and it should now be fixed.

Hmm... but now auto-revert loops forever:
updating the file -> triggers auto-revert -> your new code
saves the buffer to the file -> triggers auto-revert -> ...

I think the patch below is needed.

But I wonder why you added:

    (doc-view-make-safe-dir doc-view-cache-directory)

did it just seemed safer or have you found a concrete case that
needed it?

        Stefan

diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 5f9d4fcc2f..457e4325cf 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -457,9 +457,11 @@ doc-view--revert-buffer
                         (apply orig-fun args)
                         ;; Update the cached version of the pdf file,
                         ;; too.  This is the one that's used when
-                        ;; rendering.
-                        (doc-view-make-safe-dir doc-view-cache-directory)
-                        (write-region nil nil doc-view--buffer-file-name))))
+                        ;; rendering (bug#26996).
+                        (unless (equal buffer-file-name
+                                       doc-view--buffer-file-name)
+                          (doc-view-make-safe-dir doc-view-cache-directory)
+                          (write-region nil nil doc-view--buffer-file-name)))))
     (if (and (eq 'pdf doc-view-doc-type)
              (executable-find "pdfinfo"))
         ;; We don't want to revert if the PDF file is corrupted which