emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 3e7499c: Fix various problems in Tramp


From: Michael Albinus
Subject: master 3e7499c: Fix various problems in Tramp
Date: Fri, 19 Jun 2020 09:12:38 -0400 (EDT)

branch: master
commit 3e7499c8389b8e8900320914fe496ae2780a453e
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>

    Fix various problems in Tramp
    
    * lisp/net/tramp-compat.el (tramp-temp-name-prefix): Declare.
    (tramp-compat-make-temp-name):
    * lisp/net/tramp.el (tramp-make-tramp-temp-name): New defuns.
    
    * lisp/net/tramp.el (tramp-make-tramp-temp-file):
    * lisp/net/tramp-sh.el (tramp-find-inline-encoding)
    (tramp-maybe-open-connection, tramp-get-remote-touch)
    (tramp-get-remote-chmod-h):
    * lisp/net/tramp-smb.el (tramp-smb-handle-copy-directory): Use them.
    
    * lisp/net/tramp-sh.el (tramp-do-file-attributes-with-stat):
    Simplify shell command.  Suppress errors (interpret as nil).
    (tramp-sh-handle-make-process): Do not visit with
    `insert-file-contents'.  Delete tmp file only if exists.
    (tramp-send-command-and-read): Suppress `signal-hook-function'
    when reading expression.
---
 lisp/net/tramp-compat.el |  7 +++++++
 lisp/net/tramp-sh.el     | 50 +++++++++++++++++-------------------------------
 lisp/net/tramp-smb.el    | 11 ++---------
 lisp/net/tramp.el        | 11 +++++++----
 4 files changed, 34 insertions(+), 45 deletions(-)

diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el
index f0131d5..48670ed 100644
--- a/lisp/net/tramp-compat.el
+++ b/lisp/net/tramp-compat.el
@@ -43,6 +43,7 @@
 
 ;; `temporary-file-directory' as function is introduced with Emacs 26.1.
 (declare-function tramp-handle-temporary-file-directory "tramp")
+(defvar tramp-temp-name-prefix)
 
 ;; For not existing functions, obsolete functions, or functions with a
 ;; changed argument list, there are compiler warnings.  We want to
@@ -61,6 +62,12 @@ It is the default value of `temporary-file-directory'."
   ;; into an infloop.
   (eval (car (get 'temporary-file-directory 'standard-value))))
 
+(defsubst tramp-compat-make-temp-name ()
+  "Generate a local temporary file name (compat function)."
+  (make-temp-name
+   (expand-file-name
+    tramp-temp-name-prefix (tramp-compat-temporary-file-directory))))
+
 (defsubst tramp-compat-make-temp-file (f &optional dir-flag)
   "Create a local temporary file (compat function).
 Add the extension of F, if existing."
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index fad841a..539d048 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1336,13 +1336,8 @@ component is used as the target of the symlink."
        ;; add a space.  Apostrophes in the stat output are masked as
        ;; `tramp-stat-marker', in order to make a proper shell escape
        ;; of them in file names.
-       "( (%s %s || %s -h %s) && (%s -c "
-       "'((%s%%N%s) %%h %s %s %%X %%Y %%Z %%s %s%%A%s t %%i -1)' "
-       "%s | sed -e 's/\"/\\\\\"/g' -e 's/%s/\"/g') || echo nil)"))
-    (tramp-get-file-exists-command vec)
-    (tramp-shell-quote-argument localname)
-    (tramp-get-test-command vec)
-    (tramp-shell-quote-argument localname)
+       "(%s -c '((%s%%N%s) %%h %s %s %%X %%Y %%Z %%s %s%%A%s t %%i -1)' %s |"
+       " sed -e 's/\"/\\\\\"/g' -e 's/%s/\"/g')"))
     (tramp-get-remote-stat vec)
     tramp-stat-marker tramp-stat-marker
     (if (eq id-format 'integer)
@@ -1353,7 +1348,8 @@ component is used as the target of the symlink."
       (eval-when-compile (concat tramp-stat-marker "%G" tramp-stat-marker)))
     tramp-stat-marker tramp-stat-marker
     (tramp-shell-quote-argument localname)
-    tramp-stat-quoted-marker)))
+    tramp-stat-quoted-marker)
+   'noerror))
 
 (defun tramp-sh-handle-set-visited-file-modtime (&optional time-list)
   "Like `set-visited-file-modtime' for Tramp files."
@@ -2998,16 +2994,16 @@ STDERR can also be a file name."
                      ;; the process is deleted.
                      (when (bufferp stderr)
                        (with-current-buffer stderr
-                         (insert-file-contents-literally
-                          remote-tmpstderr 'visit))
+                         (insert-file-contents-literally remote-tmpstderr))
                        ;; Delete tmpstderr file.
                        (add-function
                         :after (process-sentinel p)
                         (lambda (_proc _msg)
-                          (with-current-buffer stderr
-                            (insert-file-contents-literally
-                             remote-tmpstderr 'visit nil nil 'replace))
-                          (delete-file remote-tmpstderr))))
+                          (when (file-exists-p remote-tmpstderr)
+                            (with-current-buffer stderr
+                              (insert-file-contents-literally
+                               remote-tmpstderr nil nil nil 'replace))
+                            (delete-file remote-tmpstderr)))))
                      ;; Return process.
                      p)))
 
@@ -4610,11 +4606,7 @@ Goes through the list `tramp-local-coding-commands' and
                                ?o (tramp-get-remote-od vec)))
                              value (replace-regexp-in-string "%" "%%" value)))
                      (when (string-match-p "\\(^\\|[^%]\\)%t" value)
-                       (setq tmpfile
-                             (make-temp-name
-                              (expand-file-name
-                               tramp-temp-name-prefix
-                               (tramp-get-remote-tmpdir vec)))
+                       (setq tmpfile (tramp-make-tramp-temp-name vec)
                              value
                              (format-spec
                               value
@@ -5053,10 +5045,7 @@ connection if a previous connection has died for some 
reason."
                         (tmpfile
                          (with-tramp-connection-property
                              (tramp-get-process vec) "temp-file"
-                           (make-temp-name
-                            (expand-file-name
-                             tramp-temp-name-prefix
-                             (tramp-compat-temporary-file-directory)))))
+                           (tramp-compat-make-temp-name)))
                         spec r-shell)
 
                    ;; Add arguments for asynchronous processes.
@@ -5276,7 +5265,10 @@ raises an error."
                    command marker (buffer-string))))))
       ;; Read the expression.
       (condition-case nil
-         (prog1 (read (current-buffer))
+         (prog1
+             (let ((signal-hook-function
+                    (unless noerror signal-hook-function)))
+               (read (current-buffer)))
            ;; Error handling.
            (when (re-search-forward "\\S-" (point-at-eol) t)
              (error nil)))
@@ -5684,10 +5676,7 @@ This command is returned only if 
`delete-by-moving-to-trash' is non-nil."
     (tramp-message vec 5 "Finding a suitable `touch' command")
     (let ((result (tramp-find-executable
                   vec "touch" (tramp-get-remote-path vec)))
-         (tmpfile
-          (make-temp-name
-           (expand-file-name
-            tramp-temp-name-prefix (tramp-get-remote-tmpdir vec)))))
+         (tmpfile (tramp-make-tramp-temp-name vec)))
       ;; Busyboxes do support the "-t" option only when they have been
       ;; built with the DESKTOP config option.  Let's check it.
       (when result
@@ -5877,10 +5866,7 @@ This command is returned only if 
`delete-by-moving-to-trash' is non-nil."
   "Check whether remote `chmod' supports nofollow argument."
   (with-tramp-connection-property vec "chmod-h"
     (tramp-message vec 5 "Finding a suitable `chmod' command with nofollow")
-    (let ((tmpfile
-          (make-temp-name
-           (expand-file-name
-            tramp-temp-name-prefix (tramp-get-remote-tmpdir vec)))))
+    (let ((tmpfile (tramp-make-tramp-temp-name vec)))
       (prog1
          (tramp-send-command-and-check
           vec
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index 3980add..357e9a2 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -438,11 +438,7 @@ pass to the OPERATION."
          (cond
           ;; We must use a local temporary directory.
           ((and t1 t2)
-           (let ((tmpdir
-                  (make-temp-name
-                   (expand-file-name
-                    tramp-temp-name-prefix
-                    (tramp-compat-temporary-file-directory)))))
+           (let ((tmpdir (tramp-compat-make-temp-name)))
              (unwind-protect
                  (progn
                    (make-directory tmpdir)
@@ -470,10 +466,7 @@ pass to the OPERATION."
                   (localname (file-name-as-directory
                               (replace-regexp-in-string
                                "\\\\" "/" (tramp-smb-get-localname v))))
-                  (tmpdir    (make-temp-name
-                              (expand-file-name
-                               tramp-temp-name-prefix
-                               (tramp-compat-temporary-file-directory))))
+                  (tmpdir    (tramp-compat-make-temp-name))
                   (args      (list (concat "//" host "/" share) "-E"))
                   (options   tramp-smb-options))
 
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 9314c43..1b50a6c 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -4726,18 +4726,21 @@ This handles also chrooted environments, which are not 
regarded as local."
          (tramp-error vec 'file-error "Directory %s not accessible" dir))
       dir)))
 
+(defun tramp-make-tramp-temp-name (vec)
+  "Generate a temporary file name on the remote host identified by VEC."
+  (make-temp-name
+   (expand-file-name tramp-temp-name-prefix (tramp-get-remote-tmpdir vec))))
+
 (defun tramp-make-tramp-temp-file (vec)
   "Create a temporary file on the remote host identified by VEC.
 Return the local name of the temporary file."
-  (let ((prefix (expand-file-name
-                tramp-temp-name-prefix (tramp-get-remote-tmpdir vec)))
-       result)
+  (let (result)
     (while (not result)
       ;; `make-temp-file' would be the natural choice for
       ;; implementation.  But it calls `write-region' internally,
       ;; which also needs a temporary file - we would end in an
       ;; infinite loop.
-      (setq result (make-temp-name prefix))
+      (setq result (tramp-make-tramp-temp-name vec))
       (if (file-exists-p result)
          (setq result nil)
        ;; This creates the file by side effect.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]