aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2020-03-21 10:30:26 +0100
committerMichael Albinus2020-03-21 10:30:26 +0100
commit8158337cc254403fbae6fed3d80064400f62f48b (patch)
tree14ce35860390df58d60763d5c5b726800755f201
parent0a22747c3f17da0e64cbb6d82aab3a14e716f0fd (diff)
downloademacs-8158337cc254403fbae6fed3d80064400f62f48b.tar.gz
emacs-8158337cc254403fbae6fed3d80064400f62f48b.zip
Fix Bug#40156 in Tramp
* 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.
-rw-r--r--lisp/net/tramp-sh.el3
-rw-r--r--test/lisp/net/tramp-tests.el9
2 files changed, 10 insertions, 2 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 7ac41d16c8b..06dca312275 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -3306,7 +3306,8 @@ STDERR can also be a file name."
3306 3306
3307 ;; If `append' is non-nil, we copy the file locally, and let 3307 ;; If `append' is non-nil, we copy the file locally, and let
3308 ;; the native `write-region' implementation do the job. 3308 ;; the native `write-region' implementation do the job.
3309 (when append (copy-file filename tmpfile 'ok)) 3309 (when (and append (file-exists-p filename))
3310 (copy-file filename tmpfile 'ok))
3310 3311
3311 ;; We say `no-message' here because we don't want the 3312 ;; We say `no-message' here because we don't want the
3312 ;; visited file modtime data to be clobbered from the temp 3313 ;; visited file modtime data to be clobbered from the temp
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index e220420d8cf..e6c6b28c58a 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -2356,7 +2356,14 @@ This checks also `file-name-as-directory', `file-name-directory',
2356 (write-region nil nil tmp-name 3)) 2356 (write-region nil nil tmp-name 3))
2357 (with-temp-buffer 2357 (with-temp-buffer
2358 (insert-file-contents tmp-name) 2358 (insert-file-contents tmp-name)
2359 (should (string-equal (buffer-string) "foobaz")))) 2359 (should (string-equal (buffer-string) "foobaz")))
2360 (delete-file tmp-name)
2361 (with-temp-buffer
2362 (insert "foo")
2363 (write-region nil nil tmp-name 'append))
2364 (with-temp-buffer
2365 (insert-file-contents tmp-name)
2366 (should (string-equal (buffer-string) "foo"))))
2360 2367
2361 ;; Write string. 2368 ;; Write string.
2362 (write-region "foo" nil tmp-name) 2369 (write-region "foo" nil tmp-name)