Commit missing file from previous commit

This commit is contained in:
Michael Albinus 2022-04-07 11:18:48 +02:00
parent 009e88e002
commit 93974198b6

View file

@ -185,7 +185,7 @@ See the variable `tramp-encoding-shell' for more information."
;; Since Emacs 26.1, `system-name' can return nil at build time if ;; Since Emacs 26.1, `system-name' can return nil at build time if
;; Emacs is compiled with "--no-build-details". We do expect it to be ;; Emacs is compiled with "--no-build-details". We do expect it to be
;; a string. (Bug#44481) ;; a string. (Bug#44481, Bug#54294)
(defconst tramp-system-name (or (system-name) "") (defconst tramp-system-name (or (system-name) "")
"The system name Tramp is running locally.") "The system name Tramp is running locally.")
@ -1409,8 +1409,11 @@ calling HANDLER.")
;; internal data structure. Convenience functions for internal ;; internal data structure. Convenience functions for internal
;; data structure. ;; data structure.
;; The basic structure for remote file names. We use a list :type, ;; The basic structure for remote file names. We use a list :type, in
;; in order to be compatible with Emacs 25. ;; order to be compatible with Emacs 25. We must autoload it in
;; tramp-loaddefs.el, because some functions, which need it, wouldn't
;; work otherwise when unloading / reloading Tramp. (Bug#50869)
;;;###tramp-autoload
(cl-defstruct (tramp-file-name (:type list) :named) (cl-defstruct (tramp-file-name (:type list) :named)
method user domain host port localname hop) method user domain host port localname hop)
@ -2186,10 +2189,14 @@ the resulting error message."
(defun tramp-test-message (fmt-string &rest arguments) (defun tramp-test-message (fmt-string &rest arguments)
"Emit a Tramp message according `default-directory'." "Emit a Tramp message according `default-directory'."
(if (tramp-tramp-file-p default-directory) (cond
(apply #'tramp-message ((tramp-tramp-file-p default-directory)
(tramp-dissect-file-name default-directory) 0 fmt-string arguments) (apply #'tramp-message
(apply #'message fmt-string arguments))) (tramp-dissect-file-name default-directory) 0 fmt-string arguments))
((tramp-file-name-p (car tramp-current-connection))
(apply #'tramp-message
(car tramp-current-connection) 0 fmt-string arguments))
(t (apply #'message fmt-string arguments))))
(put #'tramp-test-message 'tramp-suppress-trace t) (put #'tramp-test-message 'tramp-suppress-trace t)
@ -2676,17 +2683,21 @@ Falls back to normal file name handler if no Tramp file name handler exists."
(load "tramp" 'noerror 'nomessage))) (load "tramp" 'noerror 'nomessage)))
(apply operation args))) (apply operation args)))
(put #'tramp-autoload-file-name-handler 'tramp-autoload t)
;; `tramp-autoload-file-name-handler' must be registered before ;; `tramp-autoload-file-name-handler' must be registered before
;; evaluation of site-start and init files, because there might exist ;; evaluation of site-start and init files, because there might exist
;; remote files already, f.e. files kept via recentf-mode. ;; remote files already, f.e. files kept via recentf-mode.
;;;###autoload ;;;###autoload
(progn (defun tramp-register-autoload-file-name-handlers () (progn (defun tramp-register-autoload-file-name-handlers ()
"Add Tramp file name handlers to `file-name-handler-alist' during autoload." "Add Tramp file name handlers to `file-name-handler-alist' during autoload."
(add-to-list 'file-name-handler-alist (unless (rassq #'tramp-file-name-handler file-name-handler-alist)
(cons tramp-autoload-file-name-regexp (add-to-list 'file-name-handler-alist
#'tramp-autoload-file-name-handler)) (cons tramp-autoload-file-name-regexp
(put #'tramp-autoload-file-name-handler 'safe-magic t))) #'tramp-autoload-file-name-handler))
(put #'tramp-autoload-file-name-handler 'safe-magic t))))
(put #'tramp-register-autoload-file-name-handlers 'tramp-autoload t)
;;;###autoload (tramp-register-autoload-file-name-handlers) ;;;###autoload (tramp-register-autoload-file-name-handlers)
(defun tramp-use-absolute-autoload-file-names () (defun tramp-use-absolute-autoload-file-names ()
@ -2799,6 +2810,7 @@ Add operations defined in `HANDLER-alist' to `tramp-file-name-handler'."
(string-prefix-p "tramp-" (symbol-name (cdr fnh)))) (string-prefix-p "tramp-" (symbol-name (cdr fnh))))
(setq file-name-handler-alist (delq fnh file-name-handler-alist)))))) (setq file-name-handler-alist (delq fnh file-name-handler-alist))))))
(put #'tramp-unload-file-name-handlers 'tramp-autoload t)
(add-hook 'tramp-unload-hook #'tramp-unload-file-name-handlers) (add-hook 'tramp-unload-hook #'tramp-unload-file-name-handlers)
;;; File name handler functions for completion mode: ;;; File name handler functions for completion mode:
@ -3378,6 +3390,10 @@ User is always nil."
(if (file-directory-p dir) dir (file-name-directory dir)) nil (if (file-directory-p dir) dir (file-name-directory dir)) nil
(tramp-flush-directory-properties v localname))) (tramp-flush-directory-properties v localname)))
(defvar tramp-tolerate-tilde nil
"Indicator, that not expandable tilde shall be tolerated.
Let-bind it when necessary.")
(defun tramp-handle-expand-file-name (name &optional dir) (defun tramp-handle-expand-file-name (name &optional dir)
"Like `expand-file-name' for Tramp files." "Like `expand-file-name' for Tramp files."
;; If DIR is not given, use DEFAULT-DIRECTORY or "/". ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
@ -3394,6 +3410,10 @@ User is always nil."
(with-parsed-tramp-file-name name nil (with-parsed-tramp-file-name name nil
(unless (tramp-run-real-handler #'file-name-absolute-p (list localname)) (unless (tramp-run-real-handler #'file-name-absolute-p (list localname))
(setq localname (concat "/" localname))) (setq localname (concat "/" localname)))
;; Tilde expansion is not possible.
(when (and (not tramp-tolerate-tilde)
(string-match-p "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname))
(tramp-error v 'file-error "Cannot expand tilde in file `%s'" name))
;; Do not keep "/..". ;; Do not keep "/..".
(when (string-match-p "^/\\.\\.?$" localname) (when (string-match-p "^/\\.\\.?$" localname)
(setq localname "/")) (setq localname "/"))
@ -3403,7 +3423,9 @@ User is always nil."
(let ((default-directory tramp-compat-temporary-file-directory)) (let ((default-directory tramp-compat-temporary-file-directory))
(tramp-make-tramp-file-name (tramp-make-tramp-file-name
v (tramp-drop-volume-letter v (tramp-drop-volume-letter
(tramp-run-real-handler #'expand-file-name (list localname)))))))) (if (string-match-p "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
localname
(tramp-run-real-handler #'expand-file-name (list localname)))))))))
(defun tramp-handle-file-accessible-directory-p (filename) (defun tramp-handle-file-accessible-directory-p (filename)
"Like `file-accessible-directory-p' for Tramp files." "Like `file-accessible-directory-p' for Tramp files."
@ -3890,16 +3912,19 @@ Return nil when there is no lockfile."
(insert-file-contents-literally lockname) (insert-file-contents-literally lockname)
(buffer-string)))))) (buffer-string))))))
(defvar tramp-lock-pid nil
"A random nunber local for every connection.
Do not set it manually, it is used buffer-local in `tramp-get-lock-pid'.")
(defun tramp-get-lock-pid (file) (defun tramp-get-lock-pid (file)
"Determine pid for lockfile of FILE." "Determine pid for lockfile of FILE."
;; Some Tramp methods do not offer a connection process, but just a ;; Not all Tramp methods use an own process. So we use a random
;; network process as a place holder. Those processes use the ;; number, which is as good as a process id.
;; "lock-pid" connection property as fake pid, in fact it is the (with-current-buffer
;; time stamp the process is created. (tramp-get-connection-buffer (tramp-dissect-file-name file))
(let ((p (tramp-get-process (tramp-dissect-file-name file)))) (or tramp-lock-pid
(number-to-string (setq-local
(or (process-id p) tramp-lock-pid (number-to-string (random most-positive-fixnum))))))
(tramp-get-connection-property p "lock-pid" (emacs-pid))))))
(defconst tramp-lock-file-info-regexp (defconst tramp-lock-file-info-regexp
;; USER@HOST.PID[:BOOT_TIME] ;; USER@HOST.PID[:BOOT_TIME]
@ -3910,9 +3935,11 @@ Return nil when there is no lockfile."
"Like `file-locked-p' for Tramp files." "Like `file-locked-p' for Tramp files."
(when-let ((info (tramp-get-lock-file file)) (when-let ((info (tramp-get-lock-file file))
(match (string-match tramp-lock-file-info-regexp info))) (match (string-match tramp-lock-file-info-regexp info)))
(or (and (string-equal (match-string 1 info) (user-login-name)) (or ; Locked by me.
(string-equal (match-string 2 info) (system-name)) (and (string-equal (match-string 1 info) (user-login-name))
(string-equal (match-string 2 info) tramp-system-name)
(string-equal (match-string 3 info) (tramp-get-lock-pid file))) (string-equal (match-string 3 info) (tramp-get-lock-pid file)))
; User name.
(match-string 1 info)))) (match-string 1 info))))
(defun tramp-handle-lock-file (file) (defun tramp-handle-lock-file (file)
@ -3921,6 +3948,14 @@ Return nil when there is no lockfile."
;; was visited. ;; was visited.
(catch 'dont-lock (catch 'dont-lock
(unless (eq (file-locked-p file) t) ;; Locked by me. (unless (eq (file-locked-p file) t) ;; Locked by me.
(when (and buffer-file-truename
(not (verify-visited-file-modtime))
(file-exists-p file))
;; In filelock.c, `userlock--ask-user-about-supersession-threat'
;; is called, which also checks file contents. This is unwise
;; for remote files.
(ask-user-about-supersession-threat file))
(when-let ((info (tramp-get-lock-file file)) (when-let ((info (tramp-get-lock-file file))
(match (string-match tramp-lock-file-info-regexp info))) (match (string-match tramp-lock-file-info-regexp info)))
(unless (ask-user-about-lock (unless (ask-user-about-lock
@ -3933,7 +3968,7 @@ Return nil when there is no lockfile."
;; USER@HOST.PID[:BOOT_TIME] ;; USER@HOST.PID[:BOOT_TIME]
(info (info
(format (format
"%s@%s.%s" (user-login-name) (system-name) "%s@%s.%s" (user-login-name) tramp-system-name
(tramp-get-lock-pid file)))) (tramp-get-lock-pid file))))
;; Protect against security hole. ;; Protect against security hole.
@ -4198,7 +4233,9 @@ substitution. SPEC-LIST is a list of char/value pairs used for
(command (mapconcat #'tramp-shell-quote-argument command " ")) (command (mapconcat #'tramp-shell-quote-argument command " "))
;; Set cwd and environment variables. ;; Set cwd and environment variables.
(command (command
(append `("cd" ,localname "&&" "(" "env") env `(,command ")")))) (append
`("cd" ,(tramp-shell-quote-argument localname) "&&" "(" "env")
env `(,command ")"))))
;; Check for `tramp-sh-file-name-handler', because something ;; Check for `tramp-sh-file-name-handler', because something
;; is different between tramp-sh.el, and tramp-adb.el or ;; is different between tramp-sh.el, and tramp-adb.el or
@ -4464,10 +4501,7 @@ BUFFER might be a list, in this case STDERR is separated."
;; We must disable cygwin-mount file name ;; We must disable cygwin-mount file name
;; handlers and alike. ;; handlers and alike.
(tramp-run-real-handler (tramp-run-real-handler
#'substitute-in-file-name (list localname)))))))) #'substitute-in-file-name (list localname)))))))
;; "/m:h:~" does not work for completion. We use "/m:h:~/".
(if (and (stringp localname) (string-equal "~" localname))
(concat filename "/")
filename)))) filename))))
(defconst tramp-time-dont-know '(0 0 0 1000) (defconst tramp-time-dont-know '(0 0 0 1000)
@ -4871,8 +4905,9 @@ performed successfully. Any other value means an error."
(tramp-message vec 6 "\n%s" (buffer-string))) (tramp-message vec 6 "\n%s" (buffer-string)))
(if (eq exit 'ok) (if (eq exit 'ok)
(ignore-errors (ignore-errors
(and (functionp tramp-password-save-function) (when (functionp tramp-password-save-function)
(funcall tramp-password-save-function))) (funcall tramp-password-save-function)
(setq tramp-password-save-function nil)))
;; Not successful. ;; Not successful.
(tramp-clear-passwd vec) (tramp-clear-passwd vec)
(delete-process proc) (delete-process proc)
@ -5310,7 +5345,8 @@ be granted."
(offset (cond (offset (cond
((eq ?r access) 1) ((eq ?r access) 1)
((eq ?w access) 2) ((eq ?w access) 2)
((eq ?x access) 3)))) ((eq ?x access) 3)
((eq ?s access) 3))))
(dolist (suffix '("string" "integer") result) (dolist (suffix '("string" "integer") result)
(setq (setq
result result
@ -5343,7 +5379,8 @@ be granted."
(and (and
(eq access (eq access
(aref (tramp-compat-file-attribute-modes file-attr) offset)) (aref (tramp-compat-file-attribute-modes file-attr) offset))
(or (equal remote-uid (or (equal remote-uid unknown-id)
(equal remote-uid
(tramp-compat-file-attribute-user-id file-attr)) (tramp-compat-file-attribute-user-id file-attr))
(equal unknown-id (equal unknown-id
(tramp-compat-file-attribute-user-id file-attr)))) (tramp-compat-file-attribute-user-id file-attr))))
@ -5352,7 +5389,8 @@ be granted."
(eq access (eq access
(aref (tramp-compat-file-attribute-modes file-attr) (aref (tramp-compat-file-attribute-modes file-attr)
(+ offset 3))) (+ offset 3)))
(or (equal remote-gid (or (equal remote-gid unknown-id)
(equal remote-gid
(tramp-compat-file-attribute-group-id file-attr)) (tramp-compat-file-attribute-group-id file-attr))
(equal unknown-id (equal unknown-id
(tramp-compat-file-attribute-group-id (tramp-compat-file-attribute-group-id
@ -5660,7 +5698,9 @@ Invokes `password-read' if available, `read-passwd' else."
(or prompt (or prompt
(with-current-buffer (process-buffer proc) (with-current-buffer (process-buffer proc)
(tramp-check-for-regexp proc tramp-password-prompt-regexp) (tramp-check-for-regexp proc tramp-password-prompt-regexp)
(format "%s for %s " (capitalize (match-string 1)) key)))) (if (string-match-p "passphrase" (match-string 1))
(match-string 0)
(format "%s for %s " (capitalize (match-string 1)) key)))))
(auth-source-creation-prompts `((secret . ,pw-prompt))) (auth-source-creation-prompts `((secret . ,pw-prompt)))
;; Use connection-local value. ;; Use connection-local value.
(auth-sources (with-current-buffer (process-buffer proc) auth-sources)) (auth-sources (with-current-buffer (process-buffer proc) auth-sources))
@ -5872,6 +5912,8 @@ BODY is the backend specific code."
;; Maybe it's not loaded yet. ;; Maybe it's not loaded yet.
(ignore-errors (unload-feature 'tramp 'force)))) (ignore-errors (unload-feature 'tramp 'force))))
(put #'tramp-unload-tramp 'tramp-autoload t)
(provide 'tramp) (provide 'tramp)
(run-hooks 'tramp--startup-hook) (run-hooks 'tramp--startup-hook)