From dc083ebc4e34158b3be4c16d558d104c8c4e5c77 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 8 Mar 2021 10:11:22 -0500 Subject: * lisp/net/*.el: Use lexical-binding Also remove some redundant `:group` arguments. * lisp/net/eudc-export.el: Use lexical-binding. (eudc-create-bbdb-record): Use `cl-progv` and `apply` to avoid `eval`. * lisp/net/eudc-hotlist.el: Use lexical-binding. * lisp/net/eudc.el (eudc-print-attribute-value): Use `funcall` to avoid `eval`. * lisp/net/eudcb-bbdb.el: Use lexical-binding. (eudc-bbdb-filter-non-matching-record): Use `funcall` to avoid `eval`. Move `bbdb-val` binding to avoid `setq`. Use `seq-some` instead of `eval+or`. (eudc-bbdb-format-record-as-result): Use `dolist` and `pcase`. Use `funcall` to avoid `eval`. (eudc-bbdb-query-internal): Simplify a bit. * lisp/net/eudcb-ldap.el: Use lexical-binding. (eudc-ldap-get-host-parameter): Use `defalias` to avoid `eval-and-compile`. * lisp/net/telnet.el: Use lexical-binding. * lisp/net/quickurl.el: Use lexical-binding. * lisp/net/newst-ticker.el: Use lexical-binding. * lisp/net/newst-reader.el: Use lexical-binding. * lisp/net/goto-addr.el: Use lexical-binding. * lisp/net/gnutls.el: Use lexical-binding. * lisp/net/eudcb-macos-contacts.el: Use lexical-binding. * lisp/net/eudcb-mab.el: Use lexical-binding. * lisp/net/net-utils.el: Use lexical-binding. (finger): Remove unused var `found`. * lisp/net/network-stream.el (open-protocol-stream): Remove redundant `defalias`. * lisp/net/newst-plainview.el: Use lexical-binding. (newsticker-hide-entry, newsticker-show-entry): Remove unused var `is-invisible`. (w3m-fill-column, w3-maximum-line-length): Declare vars. * lisp/net/tramp.el (tramp-compute-multi-hops): * lisp/net/tramp-compat.el (tramp-compat-temporary-file-directory): * lisp/net/tramp-cmds.el (tramp-default-rename-file): * lisp/net/webjump.el (webjump): Don't forget lexical-binding for `eval`. --- lisp/net/tramp-compat.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/net/tramp-compat.el') diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index 27461e6917c..b67de1bd21b 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el @@ -70,7 +70,7 @@ It is the default value of `temporary-file-directory'." ;; We must return a local directory. If it is remote, we could run ;; into an infloop. - (eval (car (get 'temporary-file-directory 'standard-value)))) + (eval (car (get 'temporary-file-directory 'standard-value)) t)) (defsubst tramp-compat-make-temp-name () "Generate a local temporary file name (compat function)." -- cgit v1.2.3 From 70bfcbcdd328775d0fcac5ec06b797e227fc032a Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Fri, 7 May 2021 13:04:28 +0200 Subject: Tune Tramp traces * doc/misc/tramp.texi (Traces and Profiles): Describe call traces. * lisp/net/tramp-compat.el: Add `tramp-suppress-trace' property for all functions. * lisp/net/tramp.el (tramp-verbose): Adapt docstring. (tramp-file-name-method, tramp-file-name-user) (tramp-file-name-domain, tramp-file-name-host) (tramp-file-name-port, tramp-file-name-localname) (tramp-file-name-hop, tramp-file-name-user-domain) (tramp-file-name-host-port, tramp-file-name-port-or-default) (tramp-tramp-file-p, tramp-find-method, tramp-find-user) (tramp-find-host, tramp-dissect-file-name) (tramp-dissect-hop-name, tramp-debug-buffer-name) (tramp-debug-outline-level, tramp-get-debug-buffer) (tramp-get-debug-file-name, tramp-read-passwd) (tramp-clear-passwd): Add `tramp-suppress-trace' property. (tramp-debug-message): Activate call traces. * test/lisp/net/tramp-tests.el (tramp--test-instrument-test-case): Simplify. --- doc/misc/tramp.texi | 18 +++------------- lisp/net/tramp-compat.el | 5 +++-- lisp/net/tramp.el | 49 ++++++++++++++++++++++++++++++++++++++++++-- test/lisp/net/tramp-tests.el | 14 +++++-------- 4 files changed, 58 insertions(+), 28 deletions(-) (limited to 'lisp/net/tramp-compat.el') diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index ebfc14d9368..47beb90e6c6 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -5336,6 +5336,7 @@ The verbosity levels are @*@indent @w{ 8} connection properties @*@indent @w{ 9} test commands @*@indent @w{10} traces (huge) +@*@indent @w{11} call traces (maintainer only) With @code{tramp-verbose} greater than or equal to 4, messages are also written to a @value{tramp} debug buffer. Such debug buffers are @@ -5384,21 +5385,8 @@ The debug buffer is written as a file in your this option with care, because it could decrease the performance of @value{tramp} actions. -To enable stepping through @value{tramp} function call traces, they -have to be specifically enabled as shown in this code: - -@lisp -@group -(require 'trace) -(dolist (elt (all-completions "tramp-" obarray 'functionp)) - (trace-function-background (intern elt))) -(untrace-function 'tramp-read-passwd) -@end group -@end lisp - -The buffer @file{*trace-output*} contains the output from the function -call traces. Disable @code{tramp-read-passwd} to stop password -strings from being written to @file{*trace-output*}. +If @code{tramp-verbose} is greater than or equal to 11, @value{tramp} +function call traces are written to the buffer @file{*trace-output*}. @node GNU Free Documentation License diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index b67de1bd21b..54cfb6fb4a4 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el @@ -63,8 +63,6 @@ `(when (functionp ,function) (with-no-warnings (funcall ,function ,@arguments)))) -(put #'tramp-compat-funcall 'tramp-suppress-trace t) - (defsubst tramp-compat-temporary-file-directory () "Return name of directory for temporary files. It is the default value of `temporary-file-directory'." @@ -355,6 +353,9 @@ A nil value for either argument stands for the current time." (lambda (fromstring tostring instring) (replace-regexp-in-string (regexp-quote fromstring) tostring instring)))) +(dolist (elt (all-completions "tramp-compat-" obarray 'functionp)) + (put (intern elt) 'tramp-suppress-trace t)) + (add-hook 'tramp-unload-hook (lambda () (unload-feature 'tramp-loaddefs 'force) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 741ea05ceaf..9fec1514221 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -109,7 +109,8 @@ Any level x includes messages for all levels 1 .. x-1. The levels are 7 file caching 8 connection properties 9 test commands -10 traces (huge)." +10 traces (huge) +11 call traces (maintainer only)." :type 'integer) (defcustom tramp-debug-to-file nil @@ -1390,6 +1391,14 @@ calling HANDLER.") (cl-defstruct (tramp-file-name (:type list) :named) method user domain host port localname hop) +(put #'tramp-file-name-method 'tramp-suppress-trace t) +(put #'tramp-file-name-user 'tramp-suppress-trace t) +(put #'tramp-file-name-domain 'tramp-suppress-trace t) +(put #'tramp-file-name-host 'tramp-suppress-trace t) +(put #'tramp-file-name-port 'tramp-suppress-trace t) +(put #'tramp-file-name-localname 'tramp-suppress-trace t) +(put #'tramp-file-name-hop 'tramp-suppress-trace t) + (defun tramp-file-name-user-domain (vec) "Return user and domain components of VEC." (when (or (tramp-file-name-user vec) (tramp-file-name-domain vec)) @@ -1398,6 +1407,8 @@ calling HANDLER.") tramp-prefix-domain-format) (tramp-file-name-domain vec)))) +(put #'tramp-file-name-user-domain 'tramp-suppress-trace t) + (defun tramp-file-name-host-port (vec) "Return host and port components of VEC." (when (or (tramp-file-name-host vec) (tramp-file-name-port vec)) @@ -1406,12 +1417,16 @@ calling HANDLER.") tramp-prefix-port-format) (tramp-file-name-port vec)))) +(put #'tramp-file-name-host-port 'tramp-suppress-trace t) + (defun tramp-file-name-port-or-default (vec) "Return port component of VEC. If nil, return `tramp-default-port'." (or (tramp-file-name-port vec) (tramp-get-method-parameter vec 'tramp-default-port))) +(put #'tramp-file-name-port-or-default 'tramp-suppress-trace t) + ;; Comparison of file names is performed by `tramp-equal-remote'. (defun tramp-file-name-equal-p (vec1 vec2) "Check, whether VEC1 and VEC2 denote the same `tramp-file-name'." @@ -1458,6 +1473,8 @@ entry does not exist, return nil." (string-match-p tramp-file-name-regexp name) t)) +(put #'tramp-tramp-file-p 'tramp-suppress-trace t) + ;; This function bypasses the file name handler approach. It is NOT ;; recommended to use it in any package if not absolutely necessary. ;; However, it is more performant than `file-local-name', and might be @@ -1506,6 +1523,8 @@ This is METHOD, if non-nil. Otherwise, do a lookup in result (propertize result 'tramp-default t)))) +(put #'tramp-find-method 'tramp-suppress-trace t) + (defun tramp-find-user (method user host) "Return the right user string to use depending on METHOD and HOST. This is USER, if non-nil. Otherwise, do a lookup in @@ -1527,6 +1546,8 @@ This is USER, if non-nil. Otherwise, do a lookup in result (propertize result 'tramp-default t)))) +(put #'tramp-find-user 'tramp-suppress-trace t) + (defun tramp-find-host (method user host) "Return the right host string to use depending on METHOD and USER. This is HOST, if non-nil. Otherwise, do a lookup in @@ -1548,6 +1569,8 @@ This is HOST, if non-nil. Otherwise, do a lookup in result (propertize result 'tramp-default t)))) +(put #'tramp-find-host 'tramp-suppress-trace t) + (defun tramp-dissect-file-name (name &optional nodefault) "Return a `tramp-file-name' structure of NAME, a remote file name. The structure consists of method, user, domain, host, port, @@ -1612,6 +1635,8 @@ default values are used." (tramp-user-error v "Method `%s' is not supported for multi-hops." method))))))) +(put #'tramp-dissect-file-name 'tramp-suppress-trace t) + (defun tramp-dissect-hop-name (name &optional nodefault) "Return a `tramp-file-name' structure of `hop' part of NAME. See `tramp-dissect-file-name' for details." @@ -1629,6 +1654,8 @@ See `tramp-dissect-file-name' for details." ;; Return result. v)) +(put #'tramp-dissect-hop-name 'tramp-suppress-trace t) + (defun tramp-buffer-name (vec) "A name for the connection buffer VEC." (let ((method (tramp-file-name-method vec)) @@ -1805,6 +1832,8 @@ version, the function does nothing." (format "*debug tramp/%s %s@%s*" method user-domain host-port) (format "*debug tramp/%s %s*" method host-port)))) +(put #'tramp-debug-buffer-name 'tramp-suppress-trace t) + (defconst tramp-debug-outline-regexp (concat "[[:digit:]]+:[[:digit:]]+:[[:digit:]]+\\.[[:digit:]]+ " ;; Timestamp. @@ -1830,6 +1859,8 @@ Point must be at the beginning of a header line. The outline level is equal to the verbosity of the Tramp message." (1+ (string-to-number (match-string 2)))) +(put #'tramp-debug-outline-level 'tramp-suppress-trace t) + (defun tramp-get-debug-buffer (vec) "Get the debug buffer for VEC." (with-current-buffer (get-buffer-create (tramp-debug-buffer-name vec)) @@ -1855,12 +1886,16 @@ The outline level is equal to the verbosity of the Tramp message." (use-local-map special-mode-map)) (current-buffer))) +(put #'tramp-get-debug-buffer 'tramp-suppress-trace t) + (defun tramp-get-debug-file-name (vec) "Get the debug buffer for VEC." (expand-file-name (tramp-compat-string-replace "/" " " (tramp-debug-buffer-name vec)) (tramp-compat-temporary-file-directory))) +(put #'tramp-get-debug-file-name 'tramp-suppress-trace t) + (defun tramp-debug-message (vec fmt-string &rest arguments) "Append message to debug buffer of VEC. Message is formatted with FMT-STRING as control string and the remaining @@ -1871,8 +1906,8 @@ ARGUMENTS to actually emit the message (if applicable)." (with-current-buffer (tramp-get-debug-buffer vec) (goto-char (point-max)) (let ((point (point))) - ;; Headline. (when (bobp) + ;; Headline. (insert (format ";; Emacs: %s Tramp: %s -*- mode: outline; coding: utf-8; -*-" @@ -1885,6 +1920,12 @@ ARGUMENTS to actually emit the message (if applicable)." (locate-library "tramp") (or tramp-repository-branch "") (or tramp-repository-version ""))))) + ;; Traces. + (when (>= tramp-verbose 11) + (dolist (elt (all-completions "tramp-" obarray 'functionp)) + (let ((fn (intern elt))) + (unless (get fn 'tramp-suppress-trace) + (trace-function-background fn))))) ;; Delete debug file. (when (and tramp-debug-to-file (tramp-get-debug-file-name vec)) (ignore-errors (delete-file (tramp-get-debug-file-name vec))))) @@ -5408,6 +5449,8 @@ Invokes `password-read' if available, `read-passwd' else." ;; Reenable the timers. (with-timeout-unsuspend stimers)))) +(put #'tramp-read-passwd 'tramp-suppress-trace t) + (defun tramp-clear-passwd (vec) "Clear password cache for connection related to VEC." (let ((method (tramp-file-name-method vec)) @@ -5422,6 +5465,8 @@ Invokes `password-read' if available, `read-passwd' else." :host ,host-port :port ,method)) (password-cache-remove (tramp-make-tramp-file-name vec 'noloc 'nohop)))) +(put #'tramp-clear-passwd 'tramp-suppress-trace t) + (defun tramp-time-diff (t1 t2) "Return the difference between the two times, in seconds. T1 and T2 are time values (as returned by `current-time' for example)." diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 3a199469d6b..0f6f3b79800 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -195,9 +195,6 @@ is greater than 10. "^error with add-name-to-file") debug-ignored-errors)) inhibit-message) - (when trace-buffer - (dolist (elt (all-completions "tramp-" obarray 'functionp)) - (trace-function-background (intern elt)))) (unwind-protect (let ((tramp--test-instrument-test-case-p t)) ,@body) ;; Unwind forms. @@ -205,13 +202,12 @@ is greater than 10. (untrace-all)) (when (and (null tramp--test-instrument-test-case-p) (> tramp-verbose 3)) (dolist - (buf (if trace-buffer - (cons (get-buffer trace-buffer) (tramp-list-tramp-buffers)) - (tramp-list-tramp-buffers))) + (buf (append + (tramp-list-tramp-buffers) + (and trace-buffer (list (get-buffer trace-buffer))))) (with-current-buffer buf - (message ";; %s\n%s" buf (buffer-string))))) - (when trace-buffer - (kill-buffer trace-buffer))))) + (message ";; %s\n%s" buf (buffer-string))) + (kill-buffer buf)))))) (defsubst tramp--test-message (fmt-string &rest arguments) "Emit a message into ERT *Messages*." -- cgit v1.2.3 From 6d580b00e48e567ac92645e2d120769475d196ad Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Thu, 8 Jul 2021 07:48:40 +0200 Subject: Some further adaptions wrt Tramp file name locks * lisp/files.el (files--transform-file-name): Rename from `auto-save--transform-file-name'. Wrap with `save-match-data'. (make-auto-save-file-name): Use it. (make-lock-file-name): Use it. Call file name handler. * lisp/net/tramp.el (tramp-handle-write-region): * lisp/net/tramp-adb.el (tramp-adb-handle-write-region): * lisp/net/tramp-sh.el (tramp-sh-handle-write-region): * lisp/net/tramp-smb.el (tramp-smb-handle-write-region): Suppress file lock for temporary file. * lisp/net/tramp-compat.el (tramp-compat-make-lock-file-name): New defalias. * lisp/net/tramp.el (tramp-get-lock-file) (tramp-handle-lock-file, tramp-handle-unlock-file): Use it. (tramp-make-lock-name): Remove. * test/lisp/filenotify-tests.el (file-notify-test03-events-remote): Tag it :unstable temporarily. --- lisp/files.el | 122 +++++++++++++++++++++--------------------- lisp/net/tramp-adb.el | 3 +- lisp/net/tramp-compat.el | 10 ++++ lisp/net/tramp-sh.el | 7 ++- lisp/net/tramp-smb.el | 3 +- lisp/net/tramp.el | 15 +++--- test/lisp/filenotify-tests.el | 2 +- 7 files changed, 87 insertions(+), 75 deletions(-) (limited to 'lisp/net/tramp-compat.el') diff --git a/lisp/files.el b/lisp/files.el index c1377320b35..da8598f1502 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -6679,12 +6679,12 @@ Does not consider `auto-save-visited-file-name' as that variable is checked before calling this function. See also `auto-save-file-name-p'." (if buffer-file-name - (let ((handler (find-file-name-handler buffer-file-name - 'make-auto-save-file-name))) + (let ((handler (find-file-name-handler + buffer-file-name 'make-auto-save-file-name))) (if handler (funcall handler 'make-auto-save-file-name) - (auto-save--transform-file-name buffer-file-name - auto-save-file-name-transforms + (files--transform-file-name + buffer-file-name auto-save-file-name-transforms "#" "#"))) ;; Deal with buffers that don't have any associated files. (Mail ;; mode tends to create a good number of these.) @@ -6735,73 +6735,73 @@ See also `auto-save-file-name-p'." (file-error nil)) file-name))) -(defun auto-save--transform-file-name (filename transforms - prefix suffix) +(defun files--transform-file-name (filename transforms prefix suffix) "Transform FILENAME according to TRANSFORMS. See `auto-save-file-name-transforms' for the format of TRANSFORMS. PREFIX is prepended to the non-directory portion of the resulting file name, and SUFFIX is appended." - (let (result uniq) - ;; Apply user-specified translations - ;; to the file name. - (while (and transforms (not result)) - (if (string-match (car (car transforms)) filename) - (setq result (replace-match (cadr (car transforms)) t nil - filename) - uniq (car (cddr (car transforms))))) - (setq transforms (cdr transforms))) - (when result - (setq filename - (cond - ((memq uniq (secure-hash-algorithms)) - (concat - (file-name-directory result) - (secure-hash uniq filename))) - (uniq - (concat - (file-name-directory result) - (subst-char-in-string - ?/ ?! - (replace-regexp-in-string - "!" "!!" filename)))) - (t result)))) - (setq result - (if (and (eq system-type 'ms-dos) - (not (msdos-long-file-names))) - ;; We truncate the file name to DOS 8+3 limits - ;; before doing anything else, because the regexp - ;; passed to string-match below cannot handle - ;; extensions longer than 3 characters, multiple - ;; dots, and other atrocities. - (let ((fn (dos-8+3-filename - (file-name-nondirectory buffer-file-name)))) - (string-match - "\\`\\([^.]+\\)\\(\\.\\(..?\\)?.?\\|\\)\\'" - fn) - (concat (file-name-directory buffer-file-name) - prefix (match-string 1 fn) - "." (match-string 3 fn) suffix)) - (concat (file-name-directory filename) - prefix - (file-name-nondirectory filename) - suffix))) - ;; Make sure auto-save file names don't contain characters - ;; invalid for the underlying filesystem. - (expand-file-name - (if (and (memq system-type '(ms-dos windows-nt cygwin)) - ;; Don't modify remote filenames - (not (file-remote-p result))) - (convert-standard-filename result) - result)))) + (save-match-data + (let (result uniq) + ;; Apply user-specified translations to the file name. + (while (and transforms (not result)) + (if (string-match (car (car transforms)) filename) + (setq result (replace-match (cadr (car transforms)) t nil + filename) + uniq (car (cddr (car transforms))))) + (setq transforms (cdr transforms))) + (when result + (setq filename + (cond + ((memq uniq (secure-hash-algorithms)) + (concat + (file-name-directory result) + (secure-hash uniq filename))) + (uniq + (concat + (file-name-directory result) + (subst-char-in-string + ?/ ?! + (replace-regexp-in-string + "!" "!!" filename)))) + (t result)))) + (setq result + (if (and (eq system-type 'ms-dos) + (not (msdos-long-file-names))) + ;; We truncate the file name to DOS 8+3 limits before + ;; doing anything else, because the regexp passed to + ;; string-match below cannot handle extensions longer + ;; than 3 characters, multiple dots, and other + ;; atrocities. + (let ((fn (dos-8+3-filename + (file-name-nondirectory buffer-file-name)))) + (string-match + "\\`\\([^.]+\\)\\(\\.\\(..?\\)?.?\\|\\)\\'" + fn) + (concat (file-name-directory buffer-file-name) + prefix (match-string 1 fn) + "." (match-string 3 fn) suffix)) + (concat (file-name-directory filename) + prefix + (file-name-nondirectory filename) + suffix))) + ;; Make sure auto-save file names don't contain characters + ;; invalid for the underlying filesystem. + (expand-file-name + (if (and (memq system-type '(ms-dos windows-nt cygwin)) + ;; Don't modify remote filenames + (not (file-remote-p result))) + (convert-standard-filename result) + result))))) (defun make-lock-file-name (filename) "Make a lock file name for FILENAME. By default, this just prepends \".*\" to the non-directory part of FILENAME, but the transforms in `lock-file-name-transforms' are done first." - (save-match-data - (auto-save--transform-file-name - filename lock-file-name-transforms ".#" ""))) + (let ((handler (find-file-name-handler filename 'make-lock-file-name))) + (if handler + (funcall handler 'make-lock-file-name filename) + (files--transform-file-name filename lock-file-name-transforms ".#" "")))) (defun auto-save-file-name-p (filename) "Return non-nil if FILENAME can be yielded by `make-auto-save-file-name'. diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 9c1c8aca1ca..2bd13671458 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -564,7 +564,8 @@ But handle the case, if the \"test\" command is not available." (when (and append (file-exists-p filename)) (copy-file filename tmpfile 'ok) (set-file-modes tmpfile (logior (or (file-modes tmpfile) 0) #o0600))) - (write-region start end tmpfile append 'no-message) + (let (create-lockfiles) + (write-region start end tmpfile append 'no-message)) (with-tramp-progress-reporter v 3 (format-message "Moving tmp file `%s' to `%s'" tmpfile filename) diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index 54cfb6fb4a4..9d5e5f787b6 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el @@ -353,6 +353,16 @@ A nil value for either argument stands for the current time." (lambda (fromstring tostring instring) (replace-regexp-in-string (regexp-quote fromstring) tostring instring)))) +;; Function `make-lock-file-name' is new in Emacs 28.1. +(defalias 'tramp-compat-make-lock-file-name + (if (fboundp 'make-lock-file-name) + #'make-lock-file-name + (lambda (filename) + (expand-file-name + (concat + ".#" (file-name-nondirectory filename)) + (file-name-directory filename))))) + (dolist (elt (all-completions "tramp-compat-" obarray 'functionp)) (put (intern elt) 'tramp-suppress-trace t)) diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 11037227790..c65800bb0ea 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -3274,7 +3274,9 @@ implementation will be used." (or (file-directory-p localname) (file-writable-p localname))))) ;; Short track: if we are on the local host, we can run directly. - (write-region start end localname append 'no-message) + (write-region + start end localname append 'no-message + (and lockname (file-local-name lockname))) (let* ((modes (tramp-default-file-modes filename (and (eq mustbenew 'excl) 'nofollow))) @@ -3308,7 +3310,8 @@ implementation will be used." ;; on. We must ensure that `file-coding-system-alist' ;; matches `tmpfile'. (let ((file-coding-system-alist - (tramp-find-file-name-coding-system-alist filename tmpfile))) + (tramp-find-file-name-coding-system-alist filename tmpfile)) + create-lockfiles) (condition-case err (write-region start end tmpfile append 'no-message) ((error quit) diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 500245b3e19..01192db920a 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el @@ -1606,7 +1606,8 @@ errors for shares like \"C$/\", which are common in Microsoft Windows." ;; We say `no-message' here because we don't want the visited file ;; modtime data to be clobbered from the temp file. We call ;; `set-visited-file-modtime' ourselves later on. - (write-region start end tmpfile append 'no-message) + (let (create-lockfiles) + (write-region start end tmpfile append 'no-message)) (with-tramp-progress-reporter v 3 (format "Moving tmp file %s to %s" tmpfile filename) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 37d60e854f2..e9e08265fed 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3818,15 +3818,10 @@ User is always nil." ;; Result. (cons (expand-file-name filename) (cdr result))))) -(defun tramp-make-lock-name (file) - "Implement MAKE_LOCK_NAME of filelock.c." - (expand-file-name - (concat ".#" (file-name-nondirectory file)) (file-name-directory file))) - (defun tramp-get-lock-file (file) "Read lockfile of FILE. Return nil when there is no lockfile" - (let ((lockname (tramp-make-lock-name file))) + (let ((lockname (tramp-compat-make-lock-file-name file))) (or (file-symlink-p lockname) (and (file-readable-p lockname) (with-temp-buffer @@ -3873,7 +3868,7 @@ Return nil when there is no lockfile" (match-string 2 contents) (match-string 3 contents))) (throw 'dont-lock nil))) - (let ((lockname (tramp-make-lock-name file)) + (let ((lockname (tramp-compat-make-lock-file-name file)) ;; USER@HOST.PID[:BOOT_TIME] (contents (format @@ -3886,7 +3881,8 @@ Return nil when there is no lockfile" (defun tramp-handle-unlock-file (file) "Like `unlock-file' for Tramp files." - (delete-file (tramp-make-lock-name file))) + (ignore-errors + (delete-file (tramp-compat-make-lock-file-name file)))) (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix) "Like `load' for Tramp files." @@ -4470,7 +4466,8 @@ of." ;; We say `no-message' here because we don't want the visited file ;; modtime data to be clobbered from the temp file. We call ;; `set-visited-file-modtime' ourselves later on. - (write-region start end tmpfile append 'no-message) + (let (create-lockfiles) + (write-region start end tmpfile append 'no-message)) (condition-case nil (rename-file tmpfile filename 'ok-if-already-exists) (error diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el index e0fa66a5d99..6125069c6b3 100644 --- a/test/lisp/filenotify-tests.el +++ b/test/lisp/filenotify-tests.el @@ -927,7 +927,7 @@ delivered." (file-notify--test-cleanup))) (file-notify--deftest-remote file-notify-test03-events - "Check file creation/change/removal notifications for remote files.") + "Check file creation/change/removal notifications for remote files." t) (require 'autorevert) (setq auto-revert-notify-exclude-dir-regexp "nothing-to-be-excluded" -- cgit v1.2.3 From 0577bd0cf9aca220c0ecba217ac9a9522ffa990d Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sun, 25 Jul 2021 12:05:01 +0200 Subject: Use `file-name-concat' in Tramp * lisp/net/tramp-compat.el (tramp-compat-file-name-concat): New defalias. * lisp/net/tramp.el (tramp-handle-expand-file-name): * lisp/net/tramp-adb.el (tramp-adb-handle-directory-files-and-attributes): * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-expand-file-name): * lisp/net/tramp-sh.el (tramp-sh-handle-expand-file-name): * lisp/net/tramp-smb.el (tramp-smb-handle-expand-file-name): * lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-expand-file-name): Use it. --- lisp/net/tramp-adb.el | 4 ++-- lisp/net/tramp-compat.el | 14 ++++++++++++++ lisp/net/tramp-gvfs.el | 2 +- lisp/net/tramp-sh.el | 2 +- lisp/net/tramp-smb.el | 2 +- lisp/net/tramp-sudoedit.el | 2 +- lisp/net/tramp.el | 2 +- 7 files changed, 21 insertions(+), 7 deletions(-) (limited to 'lisp/net/tramp-compat.el') diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index b081e5957a3..5e0accc142a 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -327,9 +327,9 @@ arguments to pass to the OPERATION." v (format "%s -d -a -l %s %s" (tramp-adb-get-ls-command v) (tramp-shell-quote-argument - (concat (file-name-as-directory localname) ".")) + (tramp-compat-file-name-concat localname ".")) (tramp-shell-quote-argument - (concat (file-name-as-directory localname) "..")))) + (tramp-compat-file-name-concat localname "..")))) (widen))) (tramp-adb-sh-fix-ls-output) (let ((result (tramp-do-parse-file-attributes-with-ls diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index 9d5e5f787b6..6e464073379 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el @@ -363,6 +363,20 @@ A nil value for either argument stands for the current time." ".#" (file-name-nondirectory filename)) (file-name-directory filename))))) +;; Function `file-name-concat' is new in Emacs 28.1. +(defalias 'tramp-compat-file-name-concat + (if (fboundp 'file-name-concat) + #'file-name-concat + (lambda (directory &rest components) + (unless (null directory) + (let ((components (delq nil components)) + file-name-handler-alist) + (if (null components) + directory + (tramp-compat-file-name-concat + (concat (file-name-as-directory directory) (car components)) + (cdr components)))))))) + (dolist (elt (all-completions "tramp-compat-" obarray 'functionp)) (put (intern elt) 'tramp-suppress-trace t)) diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index 022fdeeb885..db561b4fd0c 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -1142,7 +1142,7 @@ file names." (when (zerop (length name)) (setq name ".")) ;; Unless NAME is absolute, concat DIR and NAME. (unless (file-name-absolute-p name) - (setq name (concat (file-name-as-directory dir) name))) + (setq name (tramp-compat-file-name-concat dir name))) ;; If NAME is not a Tramp file, run the real handler. (if (not (tramp-tramp-file-p name)) (tramp-run-real-handler #'expand-file-name (list name nil)) diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 41ab1045c24..a6569e0cdd2 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -2681,7 +2681,7 @@ the result will be a local, non-Tramp, file name." (tramp-run-real-handler #'expand-file-name (list name dir)) ;; Unless NAME is absolute, concat DIR and NAME. (unless (file-name-absolute-p name) - (setq name (concat (file-name-as-directory dir) name))) + (setq name (tramp-compat-file-name-concat dir name))) ;; If connection is not established yet, run the real handler. (if (not (tramp-connectable-p name)) (tramp-run-real-handler #'expand-file-name (list name nil)) diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 4e4f5548e20..3d5be61d3f0 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el @@ -722,7 +722,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." (when (zerop (length name)) (setq name ".")) ;; Unless NAME is absolute, concat DIR and NAME. (unless (file-name-absolute-p name) - (setq name (concat (file-name-as-directory dir) name))) + (setq name (tramp-compat-file-name-concat dir name))) ;; If NAME is not a Tramp file, run the real handler. (if (not (tramp-tramp-file-p name)) (tramp-run-real-handler #'expand-file-name (list name nil)) diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el index 45d9fab986c..177dde67cca 100644 --- a/lisp/net/tramp-sudoedit.el +++ b/lisp/net/tramp-sudoedit.el @@ -353,7 +353,7 @@ the result will be a local, non-Tramp, file name." (when (zerop (length name)) (setq name ".")) ;; Unless NAME is absolute, concat DIR and NAME. (unless (file-name-absolute-p name) - (setq name (concat (file-name-as-directory dir) name))) + (setq name (tramp-compat-file-name-concat dir name))) (with-parsed-tramp-file-name name nil ;; Tilde expansion if necessary. We cannot accept "~/", because ;; under sudo "~/" is expanded to the local user home directory diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 59c4f33f5ef..4db0b2e6723 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3346,7 +3346,7 @@ User is always nil." (when (zerop (length name)) (setq name ".")) ;; Unless NAME is absolute, concat DIR and NAME. (unless (file-name-absolute-p name) - (setq name (concat (file-name-as-directory dir) name))) + (setq name (tramp-compat-file-name-concat dir name))) ;; If NAME is not a Tramp file, run the real handler. (if (not (tramp-tramp-file-p name)) (tramp-run-real-handler #'expand-file-name (list name nil)) -- cgit v1.2.3 From 1572464b9271472b8d7a36b698541afc59b44870 Mon Sep 17 00:00:00 2001 From: Mattias EngdegÄrd Date: Tue, 10 Aug 2021 15:05:51 +0200 Subject: Tramp string-search and string-replace compatibility functions Add a `string-search` compatibility function for use in Tramp with Emacs version prior to 28, and fix the existing `string-replace` compatibility function so that it uses the right semantics. * lisp/net/tramp-compat.el (tramp-compat-string-replace): Use case-sensitive matching and literal replacement. (tramp-compat-string-search): New function. * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-file-name-all-completions): * lisp/net/tramp-sh.el (tramp-sh-handle-file-name-all-completions) (tramp-do-copy-or-rename-file-out-of-band) (tramp-sh-handle-make-process, tramp-sh-handle-process-file): * lisp/net/tramp.el (tramp-handle-make-process): Use `tramp-compat-string-search` instead of `string-match-p`. --- lisp/net/tramp-compat.el | 12 +++++++++++- lisp/net/tramp-gvfs.el | 2 +- lisp/net/tramp-sh.el | 9 +++++---- lisp/net/tramp.el | 4 ++-- 4 files changed, 19 insertions(+), 8 deletions(-) (limited to 'lisp/net/tramp-compat.el') diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index 6e464073379..b713d5eae82 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el @@ -351,7 +351,17 @@ A nil value for either argument stands for the current time." (if (fboundp 'string-replace) #'string-replace (lambda (fromstring tostring instring) - (replace-regexp-in-string (regexp-quote fromstring) tostring instring)))) + (let ((case-fold-search nil)) + (replace-regexp-in-string + (regexp-quote fromstring) tostring instring t t))))) + +;; Function `string-search' is new in Emacs 28.1. +(defalias 'tramp-compat-string-search + (if (fboundp 'string-search) + #'string-search + (lambda (needle haystack &optional start-pos) + (let ((case-fold-search nil)) + (string-match-p (regexp-quote needle) haystack start-pos))))) ;; Function `make-lock-file-name' is new in Emacs 28.1. (defalias 'tramp-compat-make-lock-file-name diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index eff14a2912f..e4f54cf4c46 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -1401,7 +1401,7 @@ If FILE-SYSTEM is non-nil, return file system attributes." (defun tramp-gvfs-handle-file-name-all-completions (filename directory) "Like `file-name-all-completions' for Tramp files." - (unless (string-match-p "/" filename) + (unless (tramp-compat-string-search "/" filename) (all-completions filename (with-parsed-tramp-file-name (expand-file-name directory) nil diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index e7d2634c587..c3b8df9e579 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -1740,7 +1740,7 @@ ID-FORMAT valid values are `string' and `integer'." ;; files. (defun tramp-sh-handle-file-name-all-completions (filename directory) "Like `file-name-all-completions' for Tramp files." - (unless (string-match-p "/" filename) + (unless (tramp-compat-string-search "/" filename) (all-completions filename (with-parsed-tramp-file-name (expand-file-name directory) nil @@ -2309,7 +2309,8 @@ The method used must be an out-of-band method." copy-args (tramp-compat-flatten-tree (mapcar - (lambda (x) (if (string-match-p " " x) (split-string x) x)) + (lambda (x) (if (tramp-compat-string-search " " x) + (split-string x) x)) copy-args)) copy-env (apply #'tramp-expand-args v 'tramp-copy-env spec) remote-copy-program @@ -2828,7 +2829,7 @@ implementation will be used." (env (dolist (elt (cons prompt process-environment) env) (or (member elt (default-toplevel-value 'process-environment)) - (if (string-match-p "=" elt) + (if (tramp-compat-string-search "=" elt) (setq env (append env `(,elt))) (setq uenv (cons elt uenv)))))) (env (setenv-internal @@ -3039,7 +3040,7 @@ implementation will be used." ;; We use as environment the difference to toplevel `process-environment'. (dolist (elt process-environment) (or (member elt (default-toplevel-value 'process-environment)) - (if (string-match-p "=" elt) + (if (tramp-compat-string-search "=" elt) (setq env (append env `(,elt))) (setq uenv (cons elt uenv))))) (setenv-internal env "INSIDE_EMACS" (tramp-inside-emacs) 'keep) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 3a392dd5f8a..fd426960fd2 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -4130,14 +4130,14 @@ substitution. SPEC-LIST is a list of char/value pairs used for (generate-new-buffer tramp-temp-buffer-name))) (env (mapcar (lambda (elt) - (when (string-match-p "=" elt) elt)) + (when (tramp-compat-string-search "=" elt) elt)) tramp-remote-process-environment)) ;; We use as environment the difference to toplevel ;; `process-environment'. (env (dolist (elt process-environment env) (when (and - (string-match-p "=" elt) + (tramp-compat-string-search "=" elt) (not (member elt (default-toplevel-value 'process-environment)))) -- cgit v1.2.3