Subject: Re: bug#66697: 30.0.50; [PATCH] desktop-save-mode with expiring remote buffers

From: Eli Zaretskii <[email-masked]>
Date: Mon, 23 Oct 2023 17:21:25 +0300

> From: Manuel Giraud <[email-masked]>
> Cc: [email-masked]
> Date: Mon, 23 Oct 2023 14:56:33 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> [...]
> 
> > So you are saying that, even though these buffers are in
> > desktop-files-not-to-save value, Emacs still asks for a password for
> > them when desktop.el saves the desktop?
> 
> Yes.
> 
> > If so, can you set debug-on-quit non-nil and when Emacs prompts for
> > the password, type C-g and post the backtrace here?
> 
> I have already (kind of) done that when trying to find out this issue:
> I've placed a 'debug' call into 'tramp-read-passwd'.  Here is what I
> get:
> 
> --8<---------------cut here---------------start------------->8---
> Debugger entered: nil
>   (let* ((default-directory tramp-compat-temporary-file-directory) (case-fold-search t) (vec (tramp-get-connection-property proc "password-vector" (process-get proc 'tramp-vector))) (key (tramp-make-tramp-file-name vec 'noloc)) (method (let* ((cl-x vec)) (progn (or (let* (...) (progn ...)) (signal 'wrong-type-argument (list ... cl-x))) (nth 1 cl-x)))) (user (or (tramp-file-name-user-domain vec) (tramp-get-connection-property key "login-as"))) (host (tramp-file-name-host-port vec)) (pw-prompt (or prompt (save-current-buffer (set-buffer (process-buffer proc)) (tramp-check-for-regexp proc tramp-password-prompt-regexp) (if (string-match-p "passphrase" (match-string 1)) (match-string 0) (format "%s for %s " (capitalize ...) key))))) (auth-source-creation-prompts (list (cons 'secret pw-prompt))) (auth-sources (buffer-local-value 'auth-sources (process-buffer proc))) auth-info auth-passwd tramp-dont-suspend-timers) (debug) (unwind-protect (or (setq tramp-password-save-function nil) (condition-case nil (progn (and (tramp-get-connection-property vec "first-password-request") (progn (setq auth-info ...) (setq tramp-password-save-function ...) (setq auth-passwd ...)))) (error nil)) (if tramp-dont-suspend-timers (progn (progn (setq auth-passwd (password-read pw-prompt key)) (setq tramp-password-save-function #'...)) auth-passwd) (let ((stimers (with-timeout-suspend)) timer-list timer-idle-list) (unwind-protect (progn (progn ... ...) auth-passwd) (with-timeout-unsuspend stimers))))) (if (tramp-string-empty-or-nil-p auth-passwd) (progn (setq tramp-password-save-function nil))) (tramp-set-connection-property vec "first-password-request" nil)))
>   tramp-read-passwd(#<process *tramp/doas root@bb*>)
>   tramp-action-password(#<process *tramp/doas root@bb*> (tramp-file-name "doas" #("root" 0 4 (tramp-default t)) nil #("bb" 0 2 (tramp-default t)) nil "~/" nil))
>   tramp-process-one-action(#<process *tramp/doas root@bb*> (tramp-file-name "doas" #("root" 0 4 (tramp-default t)) nil #("bb" 0 2 (tramp-default t)) nil "~/" nil) ((tramp-login-prompt-regexp tramp-action-login) (tramp-password-prompt-regexp tramp-action-password) (tramp-otp-password-prompt-regexp tramp-action-otp-password) (tramp-wrong-passwd-regexp tramp-action-permission-denied) (shell-prompt-pattern tramp-action-succeed) (tramp-shell-prompt-pattern tramp-action-succeed) (tramp-yesno-prompt-regexp tramp-action-yesno) (tramp-yn-prompt-regexp tramp-action-yn) (tramp-terminal-prompt-regexp tramp-action-terminal) (tramp-antispoof-regexp tramp-action-confirm-message) (tramp-security-key-confirm-regexp tramp-action-show-and-confirm-message) (tramp-process-alive-regexp tramp-action-process-alive)))
>   tramp-process-actions(#<process *tramp/doas root@bb*> (tramp-file-name "doas" #("root" 0 4 (tramp-default t)) nil #("bb" 0 2 (tramp-default t)) nil "~/" nil) 1 ((tramp-login-prompt-regexp tramp-action-login) (tramp-password-prompt-regexp tramp-action-password) (tramp-otp-password-prompt-regexp tramp-action-otp-password) (tramp-wrong-passwd-regexp tramp-action-permission-denied) (shell-prompt-pattern tramp-action-succeed) (tramp-shell-prompt-pattern tramp-action-succeed) (tramp-yesno-prompt-regexp tramp-action-yesno) (tramp-yn-prompt-regexp tramp-action-yn) (tramp-terminal-prompt-regexp tramp-action-terminal) (tramp-antispoof-regexp tramp-action-confirm-message) (tramp-security-key-confirm-regexp tramp-action-show-and-confirm-message) (tramp-process-alive-regexp tramp-action-process-alive)) 10)
>   tramp-maybe-open-connection((tramp-file-name "doas" #("root" 0 4 (tramp-default t)) nil #("bb" 0 2 (tramp-default t)) nil "~/" nil))
>   tramp-send-command((tramp-file-name "doas" #("root" 0 4 (tramp-default t)) nil #("bb" 0 2 (tramp-default t)) nil "~/" nil) #("echo ~root 2>/dev/null; echo tramp_exit_status $?" 6 10 (tramp-default t)))
>   tramp-send-command-and-check((tramp-file-name "doas" #("root" 0 4 (tramp-default t)) nil #("bb" 0 2 (tramp-default t)) nil "~/" nil) #("echo ~root" 6 10 (tramp-default t)))
>   tramp-sh-handle-get-home-directory((tramp-file-name "doas" #("root" 0 4 (tramp-default t)) nil #("bb" 0 2 (tramp-default t)) nil "~/" nil) #("root" 0 4 (tramp-default t)))
>   apply(tramp-sh-handle-get-home-directory ((tramp-file-name "doas" #("root" 0 4 (tramp-default t)) nil #("bb" 0 2 (tramp-default t)) nil "~/" nil) #("root" 0 4 (tramp-default t))))
>   tramp-sh-file-name-handler(tramp-get-home-directory (tramp-file-name "doas" #("root" 0 4 (tramp-default t)) nil #("bb" 0 2 (tramp-default t)) nil "~/" nil) #("root" 0 4 (tramp-default t)))
>   apply(tramp-sh-file-name-handler tramp-get-home-directory ((tramp-file-name "doas" #("root" 0 4 (tramp-default t)) nil #("bb" 0 2 (tramp-default t)) nil "~/" nil) #("root" 0 4 (tramp-default t))))
>   tramp-file-name-handler(tramp-get-home-directory (tramp-file-name "doas" #("root" 0 4 (tramp-default t)) nil #("bb" 0 2 (tramp-default t)) nil "~/" nil) #("root" 0 4 (tramp-default t)))
>   tramp-get-home-directory((tramp-file-name "doas" #("root" 0 4 (tramp-default t)) nil #("bb" 0 2 (tramp-default t)) nil "~/" nil) #("root" 0 4 (tramp-default t)))
>   tramp-sh-handle-expand-file-name(#("/doas:root@bb:~/" 6 10 (tramp-default t) 11 13 (tramp-default t)) nil)
>   apply(tramp-sh-handle-expand-file-name (#("/doas:root@bb:~/" 6 10 (tramp-default t) 11 13 (tramp-default t)) nil))
>   tramp-sh-file-name-handler(expand-file-name #("/doas:root@bb:~/" 6 10 (tramp-default t) 11 13 (tramp-default t)) nil)
>   apply(tramp-sh-file-name-handler expand-file-name (#("/doas:root@bb:~/" 6 10 (tramp-default t) 11 13 (tramp-default t)) nil))
>   tramp-file-name-handler(expand-file-name #("/doas:root@bb:~/" 6 10 (tramp-default t) 11 13 (tramp-default t)) nil)
>   expand-file-name(#("/doas:root@bb:~/" 6 10 (tramp-default t) 11 13 (tramp-default t)))
>   desktop-file-name(#("/doas:root@bb:~/" 6 10 (tramp-default t) 11 13 (tramp-default t)) "/home/manuel/.emacs.d/")
>   dired-desktop-buffer-misc-data("/home/manuel/.emacs.d/")
>   desktop-buffer-info(#<buffer ~</doas:root@bb:>>)
>   mapcar(desktop-buffer-info (#<buffer xterm.h> #<buffer tramp.el> #<buffer  *Minibuf-1*> #<buffer desktop.el> #<buffer ~</doas:root@bb:>> #<buffer  *Minibuf-2*> #<buffer init.el> #<buffer net> #<buffer tramp-cmds.el<emacs-repo>> #<buffer tramp-sh.el> #<buffer tramp-cmds.el<30.0.50>> #<buffer NEWS> #<buffer tramp.texi> #<buffer *info*> #<buffer files.el<emacs-repo>> #<buffer *vc-dir*<emacs-repo>> #<buffer tmp> #<buffer files.el<30.0.50>> #<buffer *eww*> #<buffer build-emacs.sh> #<buffer .xsession> #<buffer emacs.c> #<buffer terminal.c> #<buffer termhooks.h> #<buffer haikuterm.c> #<buffer xterm.c> #<buffer androidfns.c> #<buffer pgtkfns.c> #<buffer haikufns.c> #<buffer xfns.c> #<buffer widget.c> #<buffer gtkutil.c> #<buffer result> #<buffer lisp.h> #<buffer eval.c> #<buffer alloc.c> #<buffer ~</home>> #<buffer config.h> #<buffer pdumper.c> #<buffer dotfiles> #<buffer x> #<buffer bin> #<buffer *vc-dir*<sys>> #<buffer patches> #<buffer emacs<editors>> #<buffer vc.el> #<buffer bar.txt> #<buffer bar> #<buffer foo.txt> ...))
>   desktop-save("/home/manuel/.emacs.d/" nil t)
>   desktop-auto-save()
>   apply(desktop-auto-save nil)
>   timer-event-handler([t 0 30 0 nil desktop-auto-save nil idle 0 nil])
> --8<---------------cut here---------------end--------------->8---

Doesn't this tell that the problem is in dired.el, not in desktop.el?
The problematic call comes from dired-desktop-buffer-misc-data, not
from desktop.el.  So it's dired-desktop-buffer-misc-data that needs to
be fixed.

Alternatively, we could refrain calling desktop-buffer-info on buffers
for which desktop-save-buffer-p returns nil.