From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.bugs 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 Message-ID: <87h7yi12cx.fsf@gmx.de> References: <34570465-5AD0-4A4A-B862-08E5DF18E8B5@toadstyle.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="59720"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 40156-done@debbugs.gnu.org To: Sean Devlin Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 21 10:32:42 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jFaUk-000FRx-7C for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 21 Mar 2020 10:32:42 +0100 Original-Received: from localhost ([::1]:34602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFaUi-00068f-PK for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 21 Mar 2020 05:32:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49575) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFaUB-00068X-Es for bug-gnu-emacs@gnu.org; Sat, 21 Mar 2020 05:32:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jFaU8-0004we-Ra for bug-gnu-emacs@gnu.org; Sat, 21 Mar 2020 05:32:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39979) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jFaU5-0004uN-WB for bug-gnu-emacs@gnu.org; Sat, 21 Mar 2020 05:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jFaU5-0006cQ-SS for bug-gnu-emacs@gnu.org; Sat, 21 Mar 2020 05:32:01 -0400 Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Sat, 21 Mar 2020 09:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 40156 X-GNU-PR-Package: emacs Mail-Followup-To: 40156@debbugs.gnu.org, michael.albinus@gmx.de, spd@toadstyle.org Original-Received: via spool by 40156-done@debbugs.gnu.org id=D40156.158478306625372 (code D ref 40156); Sat, 21 Mar 2020 09:32:01 +0000 Original-Received: (at 40156-done) by debbugs.gnu.org; 21 Mar 2020 09:31:06 +0000 Original-Received: from localhost ([127.0.0.1]:45952 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jFaTB-0006bA-KO for submit@debbugs.gnu.org; Sat, 21 Mar 2020 05:31:06 -0400 Original-Received: from mout.gmx.net ([212.227.15.15]:56051) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jFaT8-0006ab-RK for 40156-done@debbugs.gnu.org; Sat, 21 Mar 2020 05:31:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1584783056; bh=gyTUN7iAI2+Fqu7A60k0n2Y+CJL9noOUoBeJOiWbJDY=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=a3Saae0tekbnejPryQAm/82rarbRD5568XkWjZYP3Uip+VDJwqRn1qYdVQNXmrDZC aVr4xeipzgFW5AoEMzKxT3hHXcba4zHNXExOXgSzuH2vzvb5sTznxPfuYLv54mepxs z/dP2j4XfLHK67ihU5GijZIVPi14NF8xStPDyImE= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from detlef.gmx.de ([212.86.54.10]) by mail.gmx.com (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MnaoZ-1jeVIj0Mx3-00jbwM; Sat, 21 Mar 2020 10:30:56 +0100 In-Reply-To: (Sean Devlin's message of "Fri, 20 Mar 2020 19:32:20 -0400") X-Provags-ID: V03:K1:0+3Kjx3IUHg+DgNGwZpi/xhiY3xhFhGgiU6BwRnLWk8fskeRMsh uPWXIs7CcShMuTbtvc6L39gHIE68SYbnGB+jdLEhTqrjBtjd7KmBi5xnrbFbPDc6xea8BZw pcnKIornP96+aOnMUTWGOj3dLAPQ7Kks9yMqNwf/oqghEzNALSAqE4QsNfMO74IcBOvrmV5 jtw5SscwNV/gp1AWclAJw== X-UI-Out-Filterresults: notjunk:1;V03:K0:ozThA6qIcJ0=:c+j+/ZqATChG5blsF/7rrA IBoZp7J36WcVJgMWN7h8jeiwnAS540t8coaZjcwMPY6iAWCx554PAGMHJWU+Mnwh3LErMBxnY cMXezDjTpZe3fB6mNzq9UwKeR5Uf4nVTNavFVGS0IOPz5dshIFYe6qiuAYx7wSEPkLQ1d0le4 XQJEW8+/QKRIYa6L839aN6sA2HL42xIvhrDsbUksK60HQYk1nFhP4TPD8cOAYULpihoKKRUKX cLDapTG0Fv9gxY8bUeR050L2cVB7oTqR6z4lBuECin2Na9+YHjUemxuLvL5OBKmEadzi5sjiz xy/UZHOOYoDFFCfv1oqTXUpQLD63keZwcWJAwn3KmORpO4frEeIm+Fqpe+7nLhlISnp9vbATW 59VgkK3yu4lfDPVsQNAZ7qzcJ21cmvTNY0DQ34q950ZOSiELpy1RCp5Ry1CB8DXWtBH+H3FDw 5iLgLIXTF1mB6DmJs/bId/hyqS89+MpnEghdgkGf+Y04zPnE+uDBy91aPlZp65j5LnBKWVaWq GYN43Tlh0rz43tmaONAp5BnteFcu/MIDP1lZjvxRmdIEjJZx+7If4wV3cmHmyNKRjFP7IEeHu En22gAeOrzNDJ87uQO8jg61ASD4tdXhN3E+TnWdqdz0Mv5LnOQgLirv5KJ343Ftdbg3sm4RD6 YGDcb0oA5ol+g+VaFJpvFm1IqQ38j3VcwdMc9Gsg1akgwt/+7jNF+1nnAJiT9bqkav8/Mh0X2 THKAhv9shMP8EUrn/gHIEodnEF02kQTwHi7uajPcEQ5I94QvOQJRihIjqy/Xe/VDlRGuGMEf X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:177589 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Version: 27.2 Sean Devlin 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=E2=80=99t 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Transfer-Encoding: quoted-printable diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 7ac41d16c8..06dca31227 100644 =2D-- 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 =2D-- 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) --=-=-=--