all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Albinus <michael.albinus@gmx.de>
To: Sean Devlin <spd@toadstyle.org>
Cc: 40156-done@debbugs.gnu.org
Subject: bug#40156: 26.3; append-to-file does not work on nonexistent file over ssh
Date: Sat, 21 Mar 2020 10:30:54 +0100	[thread overview]
Message-ID: <87h7yi12cx.fsf@gmx.de> (raw)
In-Reply-To: <D859A1C8-7F6F-4F07-99B8-38BAEC23FDC6@toadstyle.org> (Sean Devlin's message of "Fri, 20 Mar 2020 19:32:20 -0400")

[-- Attachment #1: Type: text/plain, Size: 996 bytes --]

Version: 27.2

Sean Devlin <spd@toadstyle.org> writes:

> Hi folks,

Hi Sean,

> I did a little digging, and I think the problem is in
> tramp-sh-handle-write-region around line 3240:
>
>> 	  ;; 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))
>
> It looks like copy-file fails if filename doesn’t exist. Adding a test
> for file existence (i.e. file-exists-p) to the condition seems to
> solve the problem, though admittedly I only tested for my own narrow
> use case.

Thanks, and yes, your analysis is correct. I've committed a respective
patch to Emacs master. I've extended also tramp-tests.el
accordingly. The patch is appended.

Since Emacs 27.1 is already in pretest, I haven't applied it there. The
next Tramp release in GNU ELPA, 2.4.3.3, will contain the patch. It is
expected end of March.

> Thanks!

Best regards, Michael.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1348 bytes --]

diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 7ac41d16c8..06dca31227 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -3306,7 +3306,8 @@ tramp-sh-handle-write-region

 	  ;; 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
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index e220420d8c..e6c6b28c58 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -2356,7 +2356,14 @@ tramp-test10-write-region
 		(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)

      reply	other threads:[~2020-03-21  9:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-20 21:14 bug#40156: 26.3; append-to-file does not work on nonexistent file over ssh Sean Devlin
2020-03-20 23:32 ` Sean Devlin
2020-03-21  9:30   ` Michael Albinus [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h7yi12cx.fsf@gmx.de \
    --to=michael.albinus@gmx.de \
    --cc=40156-done@debbugs.gnu.org \
    --cc=spd@toadstyle.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.