]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Bug#40156 in Tramp
authorMichael Albinus <michael.albinus@gmx.de>
Sat, 21 Mar 2020 09:30:26 +0000 (10:30 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Sat, 21 Mar 2020 09:30:26 +0000 (10:30 +0100)
* lisp/net/tramp-sh.el (tramp-sh-handle-write-region): Copy to temp file
only if FILENAME exists.  (Bug#40156)

* test/lisp/net/tramp-tests.el (tramp-test10-write-region): Extend test.

lisp/net/tramp-sh.el
test/lisp/net/tramp-tests.el

index 7ac41d16c8bc1c2b557483a937a4f28e03b8136a..06dca312275b135936f4378d005c5260aca0a726 100644 (file)
@@ -3306,7 +3306,8 @@ STDERR can also be a file name."
 
          ;; If `append' is non-nil, we copy the file locally, and let
          ;; the native `write-region' implementation do the job.
-         (when append (copy-file filename tmpfile 'ok))
+         (when (and append (file-exists-p filename))
+           (copy-file filename tmpfile 'ok))
 
          ;; We say `no-message' here because we don't want the
          ;; visited file modtime data to be clobbered from the temp
index e220420d8cfd6ad5da60956885130edead515be8..e6c6b28c58a4703dd45775291db08af958f2b176 100644 (file)
@@ -2356,7 +2356,14 @@ This checks also `file-name-as-directory', `file-name-directory',
                (write-region nil nil tmp-name 3))
              (with-temp-buffer
                (insert-file-contents tmp-name)
-               (should (string-equal (buffer-string) "foobaz"))))
+               (should (string-equal (buffer-string) "foobaz")))
+             (delete-file tmp-name)
+             (with-temp-buffer
+               (insert "foo")
+               (write-region nil nil tmp-name 'append))
+             (with-temp-buffer
+               (insert-file-contents tmp-name)
+               (should (string-equal (buffer-string) "foo"))))
 
            ;; Write string.
            (write-region "foo" nil tmp-name)