From unknown Fri Aug 15 12:50:54 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#35497 <35497@debbugs.gnu.org> To: bug#35497 <35497@debbugs.gnu.org> Subject: Status: [PATCH] Don't rewrite buffer contents after saving by rename Reply-To: bug#35497 <35497@debbugs.gnu.org> Date: Fri, 15 Aug 2025 19:50:54 +0000 retitle 35497 [PATCH] Don't rewrite buffer contents after saving by rename reassign 35497 emacs submitter 35497 Jonathan Tomer severity 35497 normal tag 35497 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Apr 29 19:31:10 2019 Received: (at submit) by debbugs.gnu.org; 29 Apr 2019 23:31:10 +0000 Received: from localhost ([127.0.0.1]:40105 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLFjp-0005PN-M7 for submit@debbugs.gnu.org; Mon, 29 Apr 2019 19:31:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33203) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <3r4bHXAcKDcYvw50yq3s00sxq.o0yn6s-sz6-qymo4sz6.03s@flex--jktomer.bounces.google.com>) id 1hLFZi-00058i-FG for submit@debbugs.gnu.org; Mon, 29 Apr 2019 19:20:43 -0400 Received: from lists.gnu.org ([209.51.188.17]:32957) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <3r4bHXAcKDcYvw50yq3s00sxq.o0yn6s-sz6-qymo4sz6.03s@flex--jktomer.bounces.google.com>) id 1hLFZT-00056y-Gz for submit@debbugs.gnu.org; Mon, 29 Apr 2019 19:20:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <3r4bHXAcKDcYvw50yq3s00sxq.o0yn6s-sz6-qymo4sz6.03s@flex--jktomer.bounces.google.com>) id 1hLFZP-0006SA-AK for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 19:20:27 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <3r4bHXAcKDcYvw50yq3s00sxq.o0yn6s-sz6-qymo4sz6.03s@flex--jktomer.bounces.google.com>) id 1hLFZK-00055N-6c for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 19:20:21 -0400 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]:37153) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from <3r4bHXAcKDcYvw50yq3s00sxq.o0yn6s-sz6-qymo4sz6.03s@flex--jktomer.bounces.google.com>) id 1hLFZJ-00054w-UK for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 19:20:18 -0400 Received: by mail-pl1-x64a.google.com with SMTP id p12so1265252plk.4 for ; Mon, 29 Apr 2019 16:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=23+MnmGNCQq0suX0rRZ2Q8HjMvImFlaVYwRi96PX47M=; b=MUlTKFW8Ops4LkfGtUbFNUqerpO0Ui3ekXO9+tabOyr23oa0X++KWCKztAqrYyRf3a eEpo2dauPcc6paMby0hmt2odpXgHjqpvChqNjHhQusfyT8CH9qLDqSLC6mfWuajYIhcb yQCXQkwmePK7gZUjzx5OvxLvEyM6NhMwXytYoEZWoV10WzjFpNyGWisZv8dYAYope07k 0/kQdp19GrjqFMJypWehyFsgFG5ek0VbBQOQgKrVQZoxHCQdGHXvJ7MwVEIMwI7o9I2u 3vRtIIa2C7+CoguWMRYWYZectVdoQkDifhSCc9p/zQmV5sXQ9lHO83l8JTA+OT81S3AW Qm2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=23+MnmGNCQq0suX0rRZ2Q8HjMvImFlaVYwRi96PX47M=; b=rwFcWdF3AoPpda2nNrZVRvt73Qzy4J48nYU8eLEQ3qI3ighQlhb/2ZFNRl5/OIypTy 4Jy4j7bmif5xQ0TuwKT5crl9B4T3o03ZY21UK0GTky02ne36R6xvWL9Y8OxYFeT92tM7 hgnUGTETTHfGCwWZNDmQHvn/9r9IuIs2mudwMSxSk5hKbgZetB9Nf5ZhIaWt0uzWYRei vilZx7wqzpl1nYIxm4w6eKJxIS5D1zWVUGxVvxGr+kuJ8VcG5tI72dZX25REg2kYpuFi nOghrPOcu/7Gq2aTo0CcorAPCy1rjr8sHa3LnNdRLztt0MCX82EHGNvhrPU3QJg4/J00 lHCA== X-Gm-Message-State: APjAAAUmqOtp/A9rAw/1tOLmSjdp8YeLUPwNNBZ32+e7dac7g3JA/BD9 f8bEwf/Urf+CMghexY3KGAP0UwjcG9YYOOat9R78PJNRtmwR2nD906bgFxypCKdpZ0JY/7T8i6Y bl9AGnNVXSrxdJEMQy3RsGuWUdFxsU/oZWL/lNcqPvMQ1qNSJIJe58pDPhWACB5g= X-Google-Smtp-Source: APXvYqy3pk283ywqhdhEoUWBaoinkUIArM2h0D+X3GsiSzIpKdPL4YSdsdDCCGeE95irY1J7eA30w0q/eprE X-Received: by 2002:a63:6cc7:: with SMTP id h190mr61182511pgc.350.1556580015771; Mon, 29 Apr 2019 16:20:15 -0700 (PDT) Date: Mon, 29 Apr 2019 16:20:09 -0700 Message-Id: <20190429232009.94549-1-jktomer@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog Subject: [PATCH] Don't rewrite buffer contents after saving by rename From: Jonathan Tomer To: bug-gnu-emacs@gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::64a X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 29 Apr 2019 19:31:08 -0400 Cc: Jonathan Tomer X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) When `file-precious-flag' is non-nil, files are saved by renaming a temporary file to the new name; this is an atomic operation on POSIX so other programs will not see the file in an intermediate state. Unfortunately, due to a paren-matching error introduced in change 574c05e219476912db3105fa164accd9ba12b35f, we would then write the contents again in the usual way after this rename. In addition to being wasteful, this is a serious bug: the whole point of `file-precious-flag' is to prevent race conditions with other programs that might otherwise see an empty file, but with this bug the race is actually much *more* likely to be visible: the rename will alert any inotify watchers of a change, and then the subsequent write is very likely to truncate the file just as those programs start to read it! * lisp/files.el (basic-save-buffer-2): Don't rewrite file contents after saving-by-renaming. * test/lisp/files-tests.el (files-tests-dont-rewrite-precious-files): Regression test for this change. --- etc/NEWS | 7 +++++++ lisp/files.el | 4 ++-- test/lisp/files-tests.el | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 9b32d720b6..5bfadcbbd6 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -340,6 +340,13 @@ longer. ** Multicolor fonts such as "Noto Color Emoji" can be displayed on Emacs configured with Cairo drawing and linked with cairo >=3D 1.16.0. =20 +--- +** The file-precious-flag is now respected correctly. +A bug previously caused files to be saved twice when +`file-precious-flag' or `break-hardlinks-on-save' were specified: once +by renaming a temporary file to the destination name, and then again +by truncating and rewriting the file, which is exactly what +`file-precious-flag' is supposed to avoid. =0C * Editing Changes in Emacs 27.1 =20 diff --git a/lisp/files.el b/lisp/files.el index c05d70a00e..72518e8127 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5256,7 +5256,7 @@ basic-save-buffer-2 (set-file-extended-attributes buffer-file-name (nth 1 setmodes))) (set-file-modes buffer-file-name - (logior (car setmodes) 128)))))) + (logior (car setmodes) 128))))) (let (success) (unwind-protect (progn @@ -5272,7 +5272,7 @@ basic-save-buffer-2 (and setmodes (not success) (progn (rename-file (nth 2 setmodes) buffer-file-name t) - (setq buffer-backed-up nil)))))) + (setq buffer-backed-up nil))))))) setmodes)) =20 (declare-function diff-no-select "diff" diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index ae8ea41a79..07012fea6e 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1244,5 +1244,32 @@ files-tests-file-attributes-equal (executable-find (file-name-nondirectory tmpfile)))))) (delete-file tmpfile)))) =20 +(ert-deftest files-tests-dont-rewrite-precious-files () + "Test that `file-precious-flag' forces files to be saved by +renaming only, rather than modified in-place." + (files-tests--with-temp-file temp-file-name + (with-current-buffer (find-file-noselect temp-file-name) + (let* (temp-file-events watch) + (unwind-protect + (progn + (setq watch + (file-notify-add-watch + temp-file-name '(change) + (lambda (event) + (add-to-list 'temp-file-events (cadr event) 'append= )))) + (setq-local file-precious-flag t) + (insert "foobar") + (should (null (save-buffer))) + + ;; file-notify callbacks are input events, so we need to + ;; accept input before checking results. + (sit-for 0.1) + + ;; When file-precious-flag is set, the visited file + ;; should never be modified, only renamed-to (which may + ;; appear as "renamed" and/or "created" to file-notify). + (should (not (memq 'changed temp-file-events)))) + (file-notify-rm-watch watch)))))) + (provide 'files-tests) ;;; files-tests.el ends here --=20 2.21.0.593.g511ec345e18-goog From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 30 03:18:30 2019 Received: (at 35497) by debbugs.gnu.org; 30 Apr 2019 07:18:30 +0000 Received: from localhost ([127.0.0.1]:40547 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLN26-0002vu-5G for submit@debbugs.gnu.org; Tue, 30 Apr 2019 03:18:30 -0400 Received: from mout.gmx.net ([212.227.15.18]:51793) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLN24-0002vh-Ht for 35497@debbugs.gnu.org; Tue, 30 Apr 2019 03:18:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1556608700; bh=6I/JA8qyJ+iPhircUHWWOYlwZYHYVHi59pmLytkiUFg=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=RB9qB6DaUvXK9rGCxf06oiaqI3Z5o/0mhdXWLYKRTxUO1/QLO8WtIyRWpDh+Snxqz nbI7Qvp1cUfwy3iClIkGORsDFipoeSbN2AUtNLOanZk9RFlyX7W15e2sjOUbKc9fn1 gw7BIA3b4qJnaxxqtwY9nTdUqGis7oTu3rtFCP0A= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from detlef.gmx.de ([212.86.52.91]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0LvE2c-1gca1x3u4Y-010JdV; Tue, 30 Apr 2019 09:18:20 +0200 From: Michael Albinus To: Jonathan Tomer Subject: Re: bug#35497: [PATCH] Don't rewrite buffer contents after saving by rename References: <20190429232009.94549-1-jktomer@google.com> Date: Tue, 30 Apr 2019 09:18:18 +0200 In-Reply-To: <20190429232009.94549-1-jktomer@google.com> (Jonathan Tomer's message of "Mon, 29 Apr 2019 16:20:09 -0700") Message-ID: <87pnp4t0zp.fsf@gmx.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:IRp2L5Kvd4YIQcYu51zY+wS5iIfhxfUuTZCi2K8KEZU1E5em8Ek j3IgYa9/TsRhdmaorBSRp712oxPfcfGEwOuAx4z9wu36WePwHN87u5gzjb04Al+LgtD6VY2 G1macFmAY3aLbEU9M6i9oKDB8QjuTqrbVqMJQW7V6Ks6xAi2fpyfmd6yxQbjVdOA7uSGQSw sUaUL51BQ+bv1JbMWM/lg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:cLBHMVRjcJU=:FMqSmwQs8jU759pitCrBQg rPtIokm9VfaN29rVJ+Dha7o5500nhrRn1Wy2S7u6poegjGDH/NaBfgBg/qUWn0oF0NuOoWmN2 D4L0+S1nzqh7nmK4XwNVqt8DfMn83Zp3dLBVz2iPnW1nybGfWZGiNYOVkhzlY43cYKhoAFEwg 0ddl6j7QvgFU+S909YeolshFcs7HhDYTQprH30ATEp3uiN7cj5TbLjZuJx/Q/v1t2EC/jx+Vj GMeQClHD4KOM23AjTmA//fXcI8lqWKnpjXzQczFknGVsWQy9SbVgU0RQ75jfwbB8o0cE3oie7 pDa06ipsRyUjXpVg7Etl9i8MawxOwIFR/Ng1w1JI/sEcL2CeMV4xgO8StVR0aUgqupQ3emw6U McMSUhffs7UXYQUI+NLsInOnXeVabClmI1EFdmakpFJHhvkqjzqyRNIpVC73KvylLR3gjy5Vf aeqDZ0qbm4hRJl1goqAm5iw3gW3l7wmDzuvQR5rHPRi0vuYaalvNkgx4yqnLf+40WjKN+Hgw5 uVUzYpdmaaU5IaMp0JMspvDio1oPoKzNFriAzIqtL9aMNNRDCNyw0sY9vu6mYLzi/vH71BBOd SQN82+eTVCdncRytu2cweGk+imd8BB6VDyS/M6gxwXr9U/GkhtMGAqvZuesLJ2sQqNtHO9S1Q q2HqMCKlXis27AU5nx5+5OYfBstGTFEKVG75HwzB+RfEIH5oxYl9HYpiolRYKJ+EWh56WrW8k 56kRUzFAvdNnEdgO/pFvP1WjEkwfbiF+Zg0YP5Q0gLVUV26DD0krm04AiP/LMHZENq08BDSMo OI9dLP9+e5ujsODXN+UqicKVDtwEYII3s4PX+o+S1M/9clCmDvYYODSlguU552CJK09bNg0gd X6N2raMOF5yXGu+vWkVTZYaB8KE3FYIZMuJ9njl/YsSrP+Zm8ES83C9/3FS8NhCuAiFc+7ZOy hYnES44x7fg== Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 35497 Cc: 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Jonathan Tomer writes: Hi Jonathan, Thanks for the patch. > --- a/etc/NEWS > +++ b/etc/NEWS > @@ -340,6 +340,13 @@ longer. > ** Multicolor fonts such as "Noto Color Emoji" can be displayed on > Emacs configured with Cairo drawing and linked with cairo >=3D 1.16.0. > > +--- > +** The file-precious-flag is now respected correctly. > +A bug previously caused files to be saved twice when > +`file-precious-flag' or `break-hardlinks-on-save' were specified: once > +by renaming a temporary file to the destination name, and then again > +by truncating and rewriting the file, which is exactly what > +`file-precious-flag' is supposed to avoid. > =0C > * Editing Changes in Emacs 27.1 We don't describe bug fixes in etc/NEWS. > +(ert-deftest files-tests-dont-rewrite-precious-files () > + "Test that `file-precious-flag' forces files to be saved by > +renaming only, rather than modified in-place." I haven't checked the situation with Tramp. It cares also for file-precious-flag, bug I don't remember whether it behaves as strict as you have tested here. Do you want to write a Tramp test for this? It would fit into tramp-tests.el. Best regards, Michael. From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 30 15:28:14 2019 Received: (at 35497) by debbugs.gnu.org; 30 Apr 2019 19:28:14 +0000 Received: from localhost ([127.0.0.1]:42417 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLYQH-0001f8-Rk for submit@debbugs.gnu.org; Tue, 30 Apr 2019 15:28:14 -0400 Received: from mail-ua1-f42.google.com ([209.85.222.42]:35797) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLYQG-0001ev-DX for 35497@debbugs.gnu.org; Tue, 30 Apr 2019 15:28:13 -0400 Received: by mail-ua1-f42.google.com with SMTP id g16so2494814uad.2 for <35497@debbugs.gnu.org>; Tue, 30 Apr 2019 12:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FVMi2aTH2JTTbUdJDoj5Zz0YL9XfqkkZs7jmegfZiBA=; b=N48qLt2hxCGXbj4s20WpwUxMIagiSfjzgYVWJHFgSewHoTDa/uNFDAQ3DgVpWhvZl2 A/cF2zKfPpVzmGhLElO4wKwmlbJLT4Y6wHHWk3HXhsLL//+8bj/HBi5DtqO8vwDP8aEo UBSHieiORhCFeDZJLNw5YBuvYd/yhgzt1/jRUpgpH8dNSLG+gMfTciUo1RaN2RUFnBbY eki3elqC16myRwrVHEN1l9sXSTmkl5j+SjhJrirXEyfoCn7aqzutvFVB5etM99m2GIAU bImbkuEwmSyeZnFyiPVuPwVf7akyX4se8FF46SThCwNfRZqC9mdM4u0hiR8XniJDzPiv Ybzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FVMi2aTH2JTTbUdJDoj5Zz0YL9XfqkkZs7jmegfZiBA=; b=kYqmyOyU5szcCs37YopeRU08qYFT4GYBOoVjZx16e/dXr1nbIR/zsgg5+M0TIPG97A WQrvEWYmqbxa9gsqdZkg512xE17hW2paK5MRuEUDYNUKz6axQ4i79QFwDslWDB8+f1DD 6TdtlAxfuc2z6CKOz1Cc7LPb5bFGXvVN6dAoRt+c9f6Lr+rnCHAi/bn5AVtcd3s22wP2 EMg+oztu4WpD7lsN8id4uwAC21QtWfGlwwKtfoVPIb+S4t4EH8FneJjeENTZ9UXgDOeZ 9hway/Ef/ADlkBrejgeo/YKYRbo1vCEyYROrBXvwMQp+uyf5TyyHJ+JBZifmoMuqZ696 e6nQ== X-Gm-Message-State: APjAAAX7IKuvDy60LsVEJR9JHzFI3Svi2GPg1qte4hJfLpXPIRSHG4oQ lCoqWh9OC7E+5UdpXtyNnbNiwH6WSSjuvnBxqCNs0w== X-Google-Smtp-Source: APXvYqz8qXiDpOwVzy5A29mn71ieXU3vVmIDu5367LYruqgu50Db5I+IH+f0NIhyiB9vk/0NimXxOviEEpRJ5TQrOGI= X-Received: by 2002:ab0:25cc:: with SMTP id y12mr1887035uan.113.1556652486402; Tue, 30 Apr 2019 12:28:06 -0700 (PDT) MIME-Version: 1.0 References: <20190429232009.94549-1-jktomer@google.com> <87pnp4t0zp.fsf@gmx.de> In-Reply-To: <87pnp4t0zp.fsf@gmx.de> From: Jonathan Tomer Date: Tue, 30 Apr 2019 12:27:55 -0700 Message-ID: Subject: Re: bug#35497: [PATCH] Don't rewrite buffer contents after saving by rename To: Michael Albinus Content-Type: multipart/alternative; boundary="0000000000007e34480587c46665" X-Spam-Score: -8.0 (--------) X-Debbugs-Envelope-To: 35497 Cc: 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -9.0 (---------) --0000000000007e34480587c46665 Content-Type: text/plain; charset="UTF-8" On Tue, Apr 30, 2019 at 12:18 AM Michael Albinus wrote: > Jonathan Tomer writes: > > Hi Jonathan, > > Thanks for the patch. > > > --- a/etc/NEWS > > +++ b/etc/NEWS > > @@ -340,6 +340,13 @@ longer. > > ** Multicolor fonts such as "Noto Color Emoji" can be displayed on > > Emacs configured with Cairo drawing and linked with cairo >= 1.16.0. > > > > +--- > > +** The file-precious-flag is now respected correctly. > > +A bug previously caused files to be saved twice when > > +`file-precious-flag' or `break-hardlinks-on-save' were specified: once > > +by renaming a temporary file to the destination name, and then again > > +by truncating and rewriting the file, which is exactly what > > +`file-precious-flag' is supposed to avoid. > > > > * Editing Changes in Emacs 27.1 > > We don't describe bug fixes in etc/NEWS. > Thanks, I'll fix. What's the preferred mechanism for sending an updated patch -- send an entirely new patch (relative to upstream) on a new thread, or on this thread, or a delta to apply as an additional commit on top of my previous patch? > +(ert-deftest files-tests-dont-rewrite-precious-files () > > + "Test that `file-precious-flag' forces files to be saved by > > +renaming only, rather than modified in-place." > > I haven't checked the situation with Tramp. It cares also for > file-precious-flag, bug I don't remember whether it behaves as strict as > you have tested here. Do you want to write a Tramp test for this? It > would fit into tramp-tests.el. > The actual implementation of file-precious-flag's behavior is entirely handled by basic-save-buffer-2 -- TRAMP substitutes different implementations for write-region and rename-file but the decision of which to use comes from outside. The only feature TRAMP adds is that, when file-precious-flag is set, the local and remote temp files are checksummed and the write is considered to have failed if they differ (preventing the final rename into place). I suppose the reason this is done only when file-precious-flag is set is that in the normal case it's too late to do anything about an error. In other words, I don't believe TRAMP is able to change the strictness of file-precious-flag, unless its implementation of rename-file ends up being nonatomic (which is likely the case for some remotes, but in that case an atomic write is probably impossible anyway). That said, I'm happy to add a test to tramp-tests.el as well; at the very least, with the mock tramp method we should see that the destination file is renamed-to rather than overwritten as well. Best regards, Michael. > Thanks for the fast review! --0000000000007e34480587c46665 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Apr 30, 2019 at 12:18 AM Michael = Albinus <michael.albinus@gmx.de> wr= ote:
Jonathan Tomer <jktomer@google.com> writes:

Hi Jonathan,

Thanks for the patch.

> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -340,6 +340,13 @@ longer.
>=C2=A0 ** Multicolor fonts such as "Noto Color Emoji" can be = displayed on
>=C2=A0 Emacs configured with Cairo drawing and linked with cairo >= =3D 1.16.0.
>
> +---
> +** The file-precious-flag is now respected correctly.
> +A bug previously caused files to be saved twice when
> +`file-precious-flag' or `break-hardlinks-on-save' were specif= ied: once
> +by renaming a temporary file to the destination name, and then again<= br> > +by truncating and rewriting the file, which is exactly what
> +`file-precious-flag' is supposed to avoid.
>=C2=A0
>=C2=A0 * Editing Changes in Emacs 27.1

We don't describe bug fixes in etc/NEWS.

Thanks, I'll fix. What's the preferred mechanism for sending = an updated patch -- send an entirely new patch (relative to upstream) on a = new thread, or on this thread, or a delta to apply as an additional commit = on top of my previous patch?

> +(ert-deftest files-tests-dont-rewrite-preciou= s-files ()
> +=C2=A0 "Test that `file-precious-flag' forces files to be sa= ved by
> +renaming only, rather than modified in-place."

I haven't checked the situation with Tramp. It cares also for
file-precious-flag, bug I don't remember whether it behaves as strict a= s
you have tested here. Do you want to write a Tramp test for this? It
would fit into tramp-tests.el.

The actu= al implementation of file-precious-flag's behavior is entirely handled = by basic-save-buffer-2 -- TRAMP substitutes different implementations for w= rite-region and rename-file but the decision of which to use comes from out= side. The only feature TRAMP adds is that, when file-precious-flag is set, = the local and remote temp files are checksummed and the write is considered= to have failed if they differ (preventing the final rename into place). I = suppose the reason this is done only when file-precious-flag is set is that= in the normal case it's too late to do anything about an error.
<= div>
In other words, I don't believe TRAMP is able to cha= nge the strictness of file-precious-flag, unless its implementation of rena= me-file ends up being nonatomic (which is likely the case for some remotes,= but in that case an atomic write is probably impossible anyway). That said= , I'm happy to add a test to tramp-tests.el as well; at the very least,= with the mock tramp method we should see that the destination file is rena= med-to rather than overwritten as well.

Best regards, Michael.
<= div>
Thanks for the fast review!
--0000000000007e34480587c46665-- From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 30 16:48:03 2019 Received: (at 35497) by debbugs.gnu.org; 30 Apr 2019 20:48:03 +0000 Received: from localhost ([127.0.0.1]:42513 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLZfW-0003nj-Tg for submit@debbugs.gnu.org; Tue, 30 Apr 2019 16:48:03 -0400 Received: from mout.gmx.net ([212.227.15.15]:37193) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLZfV-0003nE-BD for 35497@debbugs.gnu.org; Tue, 30 Apr 2019 16:48:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1556657272; bh=zsO2ONEmPZqJLjNOk408BCitM0LE0ZigSBBxuiRw7yQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=Edi2APgV+HFaT58dHdSJDlnjEUCX2+5fDumOnJfMsF2DfzTUMux0Jo/Hw36N0HZx/ PAot99m41nMmS7k0Nt/YnWLNnAeB0k9/hzfuO2suSDJX73K10Tb6KJSV05uKoSiHCz dz0F0+YLmfs+bJ7nMJk0FUhzX+65w2SfImCOxvKM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from detlef.gmx.de ([212.86.52.91]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0M7Gj8-1gajuA2TpO-00x1gy; Tue, 30 Apr 2019 22:47:52 +0200 From: Michael Albinus To: Jonathan Tomer Subject: Re: bug#35497: [PATCH] Don't rewrite buffer contents after saving by rename References: <20190429232009.94549-1-jktomer@google.com> <87pnp4t0zp.fsf@gmx.de> Date: Tue, 30 Apr 2019 22:47:51 +0200 In-Reply-To: (Jonathan Tomer's message of "Tue, 30 Apr 2019 12:27:55 -0700") Message-ID: <875zqvz0co.fsf@gmx.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:ZhMTmgda8o4Fm1F5B0+58ssBXwS73VQ72PhDCQdAM81FAdhHifW bQsl/pe9CJw3w1zoS+kk981IPO8Efvb235VomD63MVADLnqITLjH2LSlra60c0qX6RlLZJh URPliJtGCqzaVyH5JvYJAjE0rE3XX5SOoUx/23JrSKsOLe3TOSCOazAsGM/w/gLBMBrrOlX qqWb6i4xivCOFO75wTuIA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:e5MLxXcWJ6M=:JSftD52+Dv/pjNkBDlezh+ EL7bNZ5t/AURlgQIizHG5vJ0Qiu+BnLIARCX/k8un97VshmuwowHf5lbASYeSU/N8Vs7TLocE 4k1a4mLpBIPZLrDsWnaWR23oQg6YIqti+Ov+Q0xAUtxbHtsa4pKrz+NkmZT3z54tDvyu0sxYu 5044dd+S5bDQymISOIqk5dVqzW5h4a6+2tCp7UAMr/bHMKB8oCgT9X9cEl7uOqs7xw4S2++CA 7NWhp9Ceg5L69Fjl7mTL7a2lf1ILLfwr9q8/NWpMYW+7XO/RFT5U2bGbYI0T1dHa/AkgTKK9x MDot0fUCgTOQ6zqz3RwotrrNSgOWgJrJcjTh8LtKEtfW3Jo4V1Zq0cWHN4UfzW2n9TCOmJ477 hE8+3ZuJu2Er7icvJbMVf1o8QwYjJHGd7KAB76Izin5nburJRk6V+e/wUu0F70CF2a0/fZDxG Pzt1EINd6Vi1nIy2i4flv1KAr45CZQKE8u589MwakA3V8qhUga3DQnOUdy13iQsnfg/unkZ8H RxfuA5U55YlWmIADJXfAOw51S1Fbq8ifBxAvU/g/V+dASYkfJe8/dKw0TrQPQAAKCF0aiV6Rk hN7VskX+pDMqxZ1rqWaj2SH6hsJWv57BK3T3sowNPWMi0zH9l7pDCatt7M6SEN4UXTF4oFkb5 6AI/ebdbb1as3xwHN6vsC/JA02YR1hLSVjvI42X2p8zPQWrQsrXsoiU3bM3bJsnF8NjzE8cef 2VG5Evm/wTyuJ9HIj6cMHXvCpAmxAnI83M3o/2TT0umQY7MFquRNMLVtkOazQ2cQOKJpcxozv gZiAYZna51RIMVNV5FYs5S2KIe8Af7eNsxMXxh2mwV8yWwZqyTL09051UlW5bQkJXuIxm7Fip ceKPeCOwmNrS4f6xZr58F80EUjrkWZ4QgW8zxB7mddLAtmLzEp5OOO9vmn3NyEaDiVIrHM4ON FbTlSWzNOag== X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 35497 Cc: 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Jonathan Tomer writes: Hi Jonathan, > Thanks, I'll fix. What's the preferred mechanism for sending an > updated patch -- send an entirely new patch (relative to upstream) on > a new thread, or on this thread, or a delta to apply as an additional > commit on top of my previous patch? Please reply to these messages, keeping 35497@debbugs.gnu.org in To: or Cc:. This archives your message in the bug tracker. Usually, we appreciate a new patch relative to upstream. But in this case, not changing etc/NEWS, I believe it isn't necessary to send a new patch until there are other changes you want to show. > That said, I'm happy to add a test to tramp-tests.el as well; at the > very least, with the mock tramp method we should see that the > destination file is renamed-to rather than overwritten as well. Pls do. Btw, your new test in files-tests.el uses file notifications. Possible of course. But wouldn't it be more robust to check the inode number of the involved files, and how it changes, or not? See file-attributes how to retrieve the inode number of a file. > Thanks for the fast review! Best regards, Michael. From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 30 17:10:52 2019 Received: (at 35497) by debbugs.gnu.org; 30 Apr 2019 21:10:52 +0000 Received: from localhost ([127.0.0.1]:42570 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLa1c-0004PB-46 for submit@debbugs.gnu.org; Tue, 30 Apr 2019 17:10:52 -0400 Received: from mail-vs1-f42.google.com ([209.85.217.42]:42425) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLa1Z-0004Ow-Ge for 35497@debbugs.gnu.org; Tue, 30 Apr 2019 17:10:50 -0400 Received: by mail-vs1-f42.google.com with SMTP id b74so5745611vsd.9 for <35497@debbugs.gnu.org>; Tue, 30 Apr 2019 14:10:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=r4nY4lUaYCR+/BIrAbQDL5XjbxvGufiHUIrGLGwBwqY=; b=FLSjxTeUegAXOaavssMgf6WolXznsyki5YjRG5SxEafI9rpBpqX5M4iiNo1DzKgrmY 3f5/yRYuBPaeIDZKdYrhR8oB4cqLM13Tri+l91KWfvw5n5rbvZgfA/M7cDfoUMKSyFbi g3+hL/qgOqJUv4Xotf+o2jYfuleS+DHFUfEqYxzNgHMfQrKot4eA0YX0oX6vynOfQnvW K+hmSN0SYsWqmZnmbot01ZRTJ1tRSxzgjUfRA4ciSHo7H6O33JAfCtoRzY7ghRtz2/uA xKZL9eBpVkqitu0amwU4li9FyTJWjgR7iKt2Nt1gsww8ie2RjRsaGGFJ036R5RFcZR04 2DIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=r4nY4lUaYCR+/BIrAbQDL5XjbxvGufiHUIrGLGwBwqY=; b=MSWq8yQz2t6euV2JDIKqZ1i7CtPPRPolaxbw+znbmePNCg9nawo23IzY8rmtdqPZA3 0ihGy+eN7C2hLBR0/BR0yBTmTndS2gcf7WtVrflxIlLX6mN0PfDrs9JR1hTr7pY7Dqqn NM0jd7H1XSz5R3ld+fM5gaYYSEzmmw41q1IGW9Sgmr60gvpZFGeJwNsMTqooEiF3GQUE v2QwBIf2IXKPuYR4uMqEIJmmsCGKlvP8Be336olYgbvCF7s80GMBq4tJKZbK8MsufY+w ZxYUBHwPj5OtjU1HK9uAdb+1izCzHrYc1W3kHJ5iLLwfaPMmMZ/GKngEzOSUxSdDgaeX SADA== X-Gm-Message-State: APjAAAXuLgzCZytjm9HktQt2NaG5RZK4mhIkYwyS3QR4/IlIKFEtw7yC RUF7FLlCKsLAZajHzdD6RiP7G07+NLG/WjGgVV+f/w== X-Google-Smtp-Source: APXvYqyAZ1FyWmb8auQGMVbqoAqi+/zZZLhCLOdcF72XqpvHZDOpr98jeXRaDqjQTfJ9nis/wwMKYXZ3Y21I8tHBsnI= X-Received: by 2002:a67:f709:: with SMTP id m9mr20580953vso.171.1556658643467; Tue, 30 Apr 2019 14:10:43 -0700 (PDT) MIME-Version: 1.0 References: <20190429232009.94549-1-jktomer@google.com> <87pnp4t0zp.fsf@gmx.de> <875zqvz0co.fsf@gmx.de> In-Reply-To: <875zqvz0co.fsf@gmx.de> From: Jonathan Tomer Date: Tue, 30 Apr 2019 14:10:32 -0700 Message-ID: Subject: Re: bug#35497: [PATCH] Don't rewrite buffer contents after saving by rename To: Michael Albinus Content-Type: multipart/alternative; boundary="0000000000007b7b970587c5d53a" X-Spam-Score: -8.0 (--------) X-Debbugs-Envelope-To: 35497 Cc: 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -9.0 (---------) --0000000000007b7b970587c5d53a Content-Type: text/plain; charset="UTF-8" On Tue, Apr 30, 2019 at 1:47 PM Michael Albinus wrote: > Jonathan Tomer writes: > > Hi Jonathan, > > > Thanks, I'll fix. What's the preferred mechanism for sending an > > updated patch -- send an entirely new patch (relative to upstream) on > > a new thread, or on this thread, or a delta to apply as an additional > > commit on top of my previous patch? > > Please reply to these messages, keeping 35497@debbugs.gnu.org in To: or > Cc:. > This archives your message in the bug tracker. > > Usually, we appreciate a new patch relative to upstream. But in this > case, not changing etc/NEWS, I believe it isn't necessary to send a new > patch until there are other changes you want to show. > OK, will send along with the patch adding the TRAMP test shortly. > That said, I'm happy to add a test to tramp-tests.el as well; at the > > very least, with the mock tramp method we should see that the > > destination file is renamed-to rather than overwritten as well. > > Pls do. > > Btw, your new test in files-tests.el uses file notifications. Possible > of course. But wouldn't it be more robust to check the inode number of > the involved files, and how it changes, or not? See file-attributes how > to retrieve the inode number of a file. > I thought about checking that the inode number changes, but that wouldn't have caught this particular bug (where the file is renamed into place with the correct contents, and then rewritten in place again); indeed, that doesn't appear to be easily caught with any examination of the final state alone, since what we're looking for is to prove the *absence* of any write that fails to change the inode number. (Perhaps we could check that the modification time of the file, after write, is *less* than its inode change time, proving that there has been no ordinary write since the rename -- but in my experience, inode timestamps are not actually more reliable than inotify, and in particular this check is easily defeated by the mode-setting that happens after the write is complete, requiring care to make sure that save-buffer will not attempt to do so.) Best, Jonathan --0000000000007b7b970587c5d53a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue,= Apr 30, 2019 at 1:47 PM Michael Albinus <michael.albinus@gmx.de> wrote:
Jonathan Tomer= <jktomer@google.com> writes:

Hi Jonathan,

> Thanks, I'll fix. What's the preferred mechanism for sending a= n
> updated patch -- send an entirely new patch (relative to upstream) on<= br> > a new thread, or on this thread, or a delta to apply as an additional<= br> > commit on top of my previous patch?

Please reply to these messages, keeping 35497@de= bbugs.gnu.org in To: or Cc:.
This archives your message in the bug tracker.

Usually, we appreciate a new patch relative to upstream. But in this
case, not changing etc/NEWS, I believe it isn't necessary to send a new=
patch until there are other changes you want to show.
=
OK, will send along with the patch adding the TRAMP test sho= rtly.=C2=A0

> That said, I'm happy to add a test to tramp-tests.el as well; at t= he
> very least, with the mock tramp method we should see that the
> destination file is renamed-to rather than overwritten as well.

Pls do.

Btw, your new test in files-tests.el uses file notifications. Possible
of course. But wouldn't it be more robust to check the inode number of<= br> the involved files, and how it changes, or not? See file-attributes how
to retrieve the inode number of a file.

I thought about checking that the inode number changes, bu= t that wouldn't have
caught this particular bug (where the fi= le is renamed into place with the
correct contents, and then rewr= itten in place again); indeed, that doesn't
appear to be easi= ly caught with any examination of the final state alone,
since wh= at we're looking for is to prove the *absence* of any write that fails<= /div>
to change the inode number. (Perhaps we could check that the modi= fication time
of the file, after write, is *less* than its inode = change time, proving that
there has been no ordinary write since = the rename -- but in my experience,
inode timestamps are not actu= ally more reliable than inotify, and in
particular this check is = easily defeated by the mode-setting that happens
after the write = is complete, requiring care to make sure that save-buffer will
no= t attempt to do so.)

Best,
Jonatha= n
--0000000000007b7b970587c5d53a-- From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 30 17:21:37 2019 Received: (at 35497) by debbugs.gnu.org; 30 Apr 2019 21:21:37 +0000 Received: from localhost ([127.0.0.1]:42588 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLaC0-0004fn-Ua for submit@debbugs.gnu.org; Tue, 30 Apr 2019 17:21:37 -0400 Received: from mout.gmx.net ([212.227.17.21]:57331) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLaBy-0004fX-WE for 35497@debbugs.gnu.org; Tue, 30 Apr 2019 17:21:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1556659288; bh=EJRaNzicw0Tvfjpmb4xyI/cJi5JlDkieE+ZuoiL2WDI=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=Fu3wkEaZq6jkKWUTimqmXvzd5VmpjUNno4gnA7A/H+UkZu6Qy2GNIM+eDpa0crTVx MPUzt5saGD36AxW2NiLTfmB9fRM4DBS/9g4BGet6hBN+crHVHk2DYcGiVCIp0pX+Sc k5ZtPtlBWeC1R+ulAQYXfdMebeBsQ2t4FTwyKCj4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from detlef.gmx.de ([212.86.52.91]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MCsQ4-1hULdH3mUq-008uCL; Tue, 30 Apr 2019 23:21:28 +0200 From: Michael Albinus To: Jonathan Tomer Subject: Re: bug#35497: [PATCH] Don't rewrite buffer contents after saving by rename References: <20190429232009.94549-1-jktomer@google.com> <87pnp4t0zp.fsf@gmx.de> <875zqvz0co.fsf@gmx.de> Date: Tue, 30 Apr 2019 23:21:26 +0200 In-Reply-To: (Jonathan Tomer's message of "Tue, 30 Apr 2019 14:10:32 -0700") Message-ID: <87h8afw5nt.fsf@gmx.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:y2uBmCmPZazNMCiIZE7bmx8WxIxf6MInb7ZHN59iF8H+MJkDdeP JTTDns8sZ22f1jzO/rekrmVVLsRo4ijhRb3BiGMS0tIbMDmotZcbZhj1tGH7c3DxSIimalr qi5fTrJMSSxb+ZmToDk2lLSUY0MGyz1I68UQy1RLiqN+YRWPbU2sFN6JVBUHrtqXwTXOyNX qIeo5pw5qkn1sL7eYhy+w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:fy4SNuaS33c=:2WxbW7iPD13dyUoPpOJ+Nh Xln2dcuHaunl+sxCUinTv1+DCllwwUWxKam870tlf4vub1HVOz5rdf3g5kdEtRCpGHe4+F0Us p4h5lGQmdZ6z+VGAo8nVzznVlnHs3A5loW9uoPiL99cLdn5obQ2/r0LVCKTPYjZVGwTuCB4Nj 931mVNP+0ybxzywSRnl6oLNb9qIDRX/ceBbP2rRyOhsIz3BQiEHOCTnQrppKLfEmnnDnj44Wi TvGZNvpZ/Ul3axQHXaGDE2yQ+PauqZU1wbGhMoTzcrdtdmurV4t53jNoj7WPy5EKVzzr2ow91 qVKgjtpYnuuceipOzIgariyOT5lc+0Ctb3HERWvgMILsOwqLEowEIT7EsROYMs/4NmOhzkXKU RnjtjuA8H50h4d7UJOE2mP3H8OUhQo1QtRA+c6yR0WdwwkTIRtRuPE+a4CE7QKGCJ/g46KzU7 horNDFdEtQRmAhOyArs3xv1xlnpQAlVFLhtA7Jnj25uh9ARwqJLJ52bSsqL21C6CJRYPgytYG pExuhzi8WAS4+IwOEJcr6mbwrjfN8QcHvR/n/6HGVIH7Zdulp4l9kAyxQnmCE4LcF6p03Q8n1 zqNNOdlST+PwHfXpU4wsBEd/OLPR5dogQF1RIxxdNTLhNeOh/O7hTeEmK6WgWKZx8ZVvYBuK0 dT5IlRZIfbsniXD3ctIylNcbPdetWkQ0UjgaNYz9AN2i7SNaSUBztnkwVW9idS4Q8tLGtixoa 5G46D5bK+UyE7k2iKQGntVrNrU7XBWBmHvGh0P46nTQHLQSvhPTCXwORfeJOmfzKhl+tyUdfU h1hY8bUUr08pI6PsTqr5y1XGcwym/rGDb1e/tJ+mO5OIGaLUvcfHMQFooUv5jq/CsgNTsXMSp id6N/KGW6diP/8u/5PLG0awGMBc8o9PUl05HogQBHVhDPMxfEeMN66GIuh6NVD05u/0mjlTsS AMB8IpGcNNg== X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 35497 Cc: 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Jonathan Tomer writes: Hi Jonathan, > I thought about checking that the inode number changes, but that > wouldn't have caught this particular bug (where the file is renamed > into place with the correct contents, and then rewritten in place > again); indeed, that doesn't appear to be easily caught with any > examination of the final state alone, since what we're looking for is > to prove the *absence* of any write that fails to change the inode > number. (Perhaps we could check that the modification time of the > file, after write, is *less* than its inode change time, proving that > there has been no ordinary write since the rename -- but in my > experience, inode timestamps are not actually more reliable than > inotify, and in particular this check is easily defeated by the > mode-setting that happens after the write is complete, requiring care > to make sure that save-buffer will not attempt to do so.) I see. But pls keep in mind, that inotify is not the only file notification backend. Currently, we have six different beasts for this. > Best, > Jonathan Best regards, Michael. From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 30 18:42:28 2019 Received: (at 35497) by debbugs.gnu.org; 30 Apr 2019 22:42:28 +0000 Received: from localhost ([127.0.0.1]:42739 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLbSG-0006fx-8n for submit@debbugs.gnu.org; Tue, 30 Apr 2019 18:42:28 -0400 Received: from mail-ua1-f67.google.com ([209.85.222.67]:46907) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLbSE-0006fd-ML for 35497@debbugs.gnu.org; Tue, 30 Apr 2019 18:42:27 -0400 Received: by mail-ua1-f67.google.com with SMTP id n23so4981597uap.13 for <35497@debbugs.gnu.org>; Tue, 30 Apr 2019 15:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OJ7vAArWM0m8eMLWyvhQyK9NS+CeevnB0qRbJ1VJE/Y=; b=W/oRSqUOvtLG3LevsShy6wToA+4yztcxGIFXz0EPMFpJoSI6U5dpAx3sAbARNMkS2G m80Sp+TMWwfoSoe4jwU3qxuVJRiWgIpx8OJ/xLUwYC8OmePbqH9w/3sfL7byjNt2xPT1 j58+ZrUeFRJ7aOmvemwO6C1PHgTD++anCo1v5JKDSuyxfdp1aHADL1nFiF1+s7jI8/SW m3pcRgN2ipVHehCOERPud/upC21mjJIc+9Cm60Cg1PXidTL/1wCZNHFC6CmKzmp5khGg L5m6UGoigwqwv00YaflK9EeyEcfsdZOEMhHt7hrDVRLxNHxVKtVa9qIMyWo5fKPToDT6 DoRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OJ7vAArWM0m8eMLWyvhQyK9NS+CeevnB0qRbJ1VJE/Y=; b=g72c/TCSzkTaHclSLPBFmzx5W33s8R5bCEZZbSd0bra5nMDigLTzJwhREHXXPVzOT1 NliZ8aYazAtq7YQlS69M9jY5pJiRFL7CtYSpkOF9nkyoVuof4tBGXg4v88jQkpd8UNVI nzoBVb3mQJ6jOUFiHBvRE2WEAoXjkPNGCJIuHf2H4EJNlC+bEHLjsEc8gOnv2SJiRMeh 9MhlJq7ST0VxglaP3A8WvqibNy75nFiCPpEAG1AmMH27zKr+dai3veKaRXl9/ha8KZJX EYt2cvY+K8CO6wX34wdH7kQMkISEkIAG16JaSW7Vkw8FPWFtonqbS2SR4h03Cu2ft375 jEew== X-Gm-Message-State: APjAAAU2QJeMmvR72JIJf3YO+brNMGtlJNtQ6BMF+55GuvlULk/monYT akx/TZixFBSd5oQGDc61RQcKsxtsabPLi+wL9Fkt8g== X-Google-Smtp-Source: APXvYqz9ii+4iCiPD7hAn08Syoob0GkXDrQpAT0v5ro3fNJTIbApHlOLz8fq6LWGuopACetCz592YENys75Xrv3kN5c= X-Received: by 2002:ab0:25cc:: with SMTP id y12mr2406247uan.113.1556664139999; Tue, 30 Apr 2019 15:42:19 -0700 (PDT) MIME-Version: 1.0 References: <20190429232009.94549-1-jktomer@google.com> <87pnp4t0zp.fsf@gmx.de> <875zqvz0co.fsf@gmx.de> <87h8afw5nt.fsf@gmx.de> In-Reply-To: <87h8afw5nt.fsf@gmx.de> From: Jonathan Tomer Date: Tue, 30 Apr 2019 15:42:08 -0700 Message-ID: Subject: Re: bug#35497: [PATCH] Don't rewrite buffer contents after saving by rename To: Michael Albinus Content-Type: multipart/alternative; boundary="00000000000019f0ef0587c71d26" X-Spam-Score: -8.0 (--------) X-Debbugs-Envelope-To: 35497 Cc: 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -9.0 (---------) --00000000000019f0ef0587c71d26 Content-Type: text/plain; charset="UTF-8" On Tue, Apr 30, 2019 at 2:21 PM Michael Albinus wrote: > Jonathan Tomer writes: > > Hi Jonathan, > > > I thought about checking that the inode number changes, but that > > wouldn't have caught this particular bug (where the file is renamed > > into place with the correct contents, and then rewritten in place > > again); indeed, that doesn't appear to be easily caught with any > > examination of the final state alone, since what we're looking for is > > to prove the *absence* of any write that fails to change the inode > > number. (Perhaps we could check that the modification time of the > > file, after write, is *less* than its inode change time, proving that > > there has been no ordinary write since the rename -- but in my > > experience, inode timestamps are not actually more reliable than > > inotify, and in particular this check is easily defeated by the > > mode-setting that happens after the write is complete, requiring care > > to make sure that save-buffer will not attempt to do so.) > > I see. But pls keep in mind, that inotify is not the only file > notification backend. Currently, we have six different beasts for this. > I was a bit worried about that; I considered disabling the test when file-notify--library is not inotify, but instead designed the test so that *missed* notifications would not cause it to fail, and I believe the other implementations at least should not record a spurious "changed" notification. It's still not ideal but it is the best regression coverage I can think of here. I don't have BSD or win32 machines available to test on, so if you can point me to a way to test this change on those targets I'm happy to run the new tests. Updated patch incoming. --00000000000019f0ef0587c71d26 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue,= Apr 30, 2019 at 2:21 PM Michael Albinus <michael.albinus@gmx.de> wrote:
Jonathan Tomer= <jktomer@google.com> writes:

Hi Jonathan,

> I thought about checking that the inode number changes, but that
> wouldn't have caught this particular bug (where the file is rename= d
> into place with the correct contents, and then rewritten in place
> again); indeed, that doesn't appear to be easily caught with any > examination of the final state alone, since what we're looking for= is
> to prove the *absence* of any write that fails to change the inode
> number. (Perhaps we could check that the modification time of the
> file, after write, is *less* than its inode change time, proving that<= br> > there has been no ordinary write since the rename -- but in my
> experience, inode timestamps are not actually more reliable than
> inotify, and in particular this check is easily defeated by the
> mode-setting that happens after the write is complete, requiring care<= br> > to make sure that save-buffer will not attempt to do so.)

I see. But pls keep in mind, that inotify is not the only file
notification backend. Currently, we have six different beasts for this.
=

I was a bit worried about that; I con= sidered disabling the test when
file-notify--library is not inoti= fy, but instead designed the test so that
*missed* notifications = would not cause it to fail, and I believe the other
implementatio= ns at least should not record a spurious "changed" notification.<= /div>
It's still not ideal but it is the best regression coverage I= can think of here.

I don't have BS= D or win32 machines available to test on, so if you can point
me = to a way to test this change on those targets I'm happy to run the new<= /div>
tests.

Updated patch incoming.
--00000000000019f0ef0587c71d26-- From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 30 20:27:29 2019 Received: (at 35497) by debbugs.gnu.org; 1 May 2019 00:27:30 +0000 Received: from localhost ([127.0.0.1]:42837 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLd5t-0000i9-IA for submit@debbugs.gnu.org; Tue, 30 Apr 2019 20:27:29 -0400 Received: from mail-qt1-f202.google.com ([209.85.160.202]:54324) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <36ufIXAcKBckyz831t6v33v0t.r31IKJOMstqq9v7.v29.36v@flex--jktomer.bounces.google.com>) id 1hLd5r-0000hx-Ve for 35497@debbugs.gnu.org; Tue, 30 Apr 2019 20:27:28 -0400 Received: by mail-qt1-f202.google.com with SMTP id f53so2772992qte.21 for <35497@debbugs.gnu.org>; Tue, 30 Apr 2019 17:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=LgIFsCdye2xihXhY1+wM+W3ylnFT3SM7VkGDs+Z8t6Q=; b=O9MzM7Ix4ON7QS/As0oX43GobDEithaXnNmlX1x1Ge9bWK+kqe2YtOkaAGtlv78DNh L0HJ1qcrK5At1dXemQRsREgxJevkOqprjDElMc3SUX8tRjMf1wyn7VlrjpwZYbWmIUra XjS7IGYyaGZKRkAxJYDym6heUbSL6KjRbcyaru8A8IT0wGMaVyGKlf0aK2Rq98rvYR+9 bO85SSjTQlnr9N+PKrzZ0qaux/kPAFwmWQ0pO2NueylbfQ8lyO+kSoyuKIpD7WGavMbD wc9mLh7a2X1LDYh1VldZm2tR0SDtR9EGrlk/5mvXkVrz3Czhhkv1mKKf/uzDptbDSnOv 4/Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LgIFsCdye2xihXhY1+wM+W3ylnFT3SM7VkGDs+Z8t6Q=; b=tcs1UwVsEa4u4ETskng90dxhPIiTCAtXr7nW/9WPuf3uVr0QRZaYt7R+/vUlD+B+gR 3roIWrd3lrTLTPrT8hILdjOINfDnfblh7UutbA9KMm+TIgKo0LAf9Jcngr0bHcbio/Ez UmUhupPYln5Xkn1u9FEc5amj3zPr0E3q70VwVhAa/cywMFawNB2cCckeaR5YkRpp0YBS RekZAPkd1740hHDFcuWDfCAb+ITCVPWJl3gCQqVXq0W8+QgSfY2ShF6SQNEZT8RZO+bx ziWf3UPCa14DxqofSjwnnuNxQBzL3su62Df9gsWwkdLNFPAtjUDJATsYsCoNq55sZRxj 0IYg== X-Gm-Message-State: APjAAAVjVBHzcCoDwaiyWhQDsw1BcL50JJFIeafpzw77ZIX582AZ6cwt i9OzmAy9AEBXCauD+PMDF5zh8AXMQcHotgtDWzdUDv9KVHQIwJCn7Yl5FJmmqOtO95t1sr4IRQX XWayEzznp/7clpSAov/i8r5JjRr0AnoS2nd8R9LUtH3plArE0dZvudZMaPlgv7/E= X-Google-Smtp-Source: APXvYqw6xx10NFuCzwHG8VW7pQACQ0aT7u65fJVPHjouyEBoDxWQHEv+cqWzFbR7c4XnF7cDqB/4lim7c9bp X-Received: by 2002:a0c:9666:: with SMTP id 35mr29615130qvy.214.1556670442350; Tue, 30 Apr 2019 17:27:22 -0700 (PDT) Date: Tue, 30 Apr 2019 17:26:42 -0700 In-Reply-To: <87h8afw5nt.fsf@gmx.de> Message-Id: <20190501002641.71320-1-jktomer@google.com> Mime-Version: 1.0 References: <87h8afw5nt.fsf@gmx.de> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog Subject: [PATCH v2] Don't rewrite buffer contents after saving by rename From: Jonathan Tomer To: 35497@debbugs.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 35497 Cc: Jonathan Tomer X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) When `file-precious-flag' is non-nil, files are saved by renaming a temporary file to the new name; this is an atomic operation on POSIX so other programs will not see the file in an intermediate state. Unfortunately, due to a paren-matching error introduced in change 574c05e219476912db3105fa164accd9ba12b35f, we would then write the contents again in the usual way after this rename. In addition to being wasteful, this is a serious bug: the whole point of `file-precious-flag' is to prevent race conditions with other programs that might otherwise see an empty file, but with this bug the race is actually much *more* likely to be visible: the rename will alert any inotify watchers of a change, and then the subsequent write is very likely to truncate the file just as those programs start to read it! * lisp/files.el (basic-save-buffer-2): Don't rewrite file contents after saving-by-renaming. * test/lisp/files-tests.el (files-tests-dont-rewrite-precious-files): * test/lisp/net/tramp-tests.el (tramp-test46-file-precious-flag): Regression tests for this change. --- lisp/files.el | 4 ++-- test/lisp/files-tests.el | 26 ++++++++++++++++++++++++++ test/lisp/net/tramp-tests.el | 28 ++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index c05d70a00e..72518e8127 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5256,7 +5256,7 @@ basic-save-buffer-2 (set-file-extended-attributes buffer-file-name (nth 1 setmodes))) (set-file-modes buffer-file-name - (logior (car setmodes) 128)))))) + (logior (car setmodes) 128))))) (let (success) (unwind-protect (progn @@ -5272,7 +5272,7 @@ basic-save-buffer-2 (and setmodes (not success) (progn (rename-file (nth 2 setmodes) buffer-file-name t) - (setq buffer-backed-up nil)))))) + (setq buffer-backed-up nil))))))) setmodes)) (declare-function diff-no-select "diff" diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index ae8ea41a79..15f2a760c4 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1244,5 +1244,31 @@ files-tests-file-attributes-equal (executable-find (file-name-nondirectory tmpfile)))))) (delete-file tmpfile)))) +(ert-deftest files-tests-dont-rewrite-precious-files () + "Test that `file-precious-flag' forces files to be saved by +renaming only, rather than modified in-place." + (files-tests--with-temp-file temp-file-name + (let* (temp-file-events + (watch (file-notify-add-watch + temp-file-name '(change) + (lambda (event) + (push (cadr event) temp-file-events))))) + (unwind-protect + (with-current-buffer (find-file-noselect temp-file-name) + (setq-local file-precious-flag t) + (insert "foobar") + (should (null (save-buffer))) + + ;; file-notify callbacks are triggered by input events, + ;; so we need to accept input before checking results. + (with-timeout (3.0 (ignore)) + (while (read-event nil nil 0.01) (ignore))) + + ;; When file-precious-flag is set, the visited file + ;; should never be modified, only renamed-to (which may + ;; appear as "renamed" and/or "created" to file-notify). + (should (not (memq 'changed temp-file-events)))) + (file-notify-rm-watch watch))))) + (provide 'files-tests) ;;; files-tests.el ends here diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index cba697da18..1ca98520b3 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -44,6 +44,7 @@ (require 'dired) (require 'ert) (require 'ert-x) +(require 'filenotify) (require 'tramp) (require 'vc) (require 'vc-bzr) @@ -5741,6 +5742,33 @@ tramp--test-asynchronous-requests-timeout (ignore-errors (all-completions "tramp" (symbol-value x))) (ert-fail (format "Hook `%s' still contains Tramp function" x)))))) +(ert-deftest tramp-test46-file-precious-flag () + "Check that file-precious-flag is respected with Tramp in use." + (let* ((temp-file (make-temp-file "emacs")) + (remote-file (concat "/mock:localhost:" temp-file)) + temp-file-events + (watch + (file-notify-add-watch + temp-file '(change) + (lambda (event) + (push (cadr event) 'temp-file-events))))) + (unwind-protect + (with-current-buffer (find-file-noselect remote-file) + (setq-local file-precious-flag t) + (insert "foobar") + (should (null (save-buffer))) + + ;; file-notify callbacks are triggered by input events, so + ;; we need to accept input before checking results. + (with-timeout (3.0 (ignore)) + (while (read-event nil nil 0.01) (ignore))) + + ;; When file-precious-flag is set, the visited file should + ;; never be modified, only renamed-to. + (should (not (memq 'changed temp-file-events))))) + (file-notify-rm-watch watch) + (delete-file temp-file))) + (defun tramp-test-all (&optional interactive) "Run all tests for \\[tramp]." (interactive "p") -- 2.21.0.593.g511ec345e18-goog From debbugs-submit-bounces@debbugs.gnu.org Wed May 01 13:48:56 2019 Received: (at 35497) by debbugs.gnu.org; 1 May 2019 17:48:56 +0000 Received: from localhost ([127.0.0.1]:44846 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLtLj-0002r1-Np for submit@debbugs.gnu.org; Wed, 01 May 2019 13:48:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54899) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLtLh-0002qn-Pv for 35497@debbugs.gnu.org; Wed, 01 May 2019 13:48:54 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:57286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLtLa-0006aY-Qm; Wed, 01 May 2019 13:48:48 -0400 Received: from [176.228.60.248] (port=2175 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hLtLZ-0004ky-UU; Wed, 01 May 2019 13:48:46 -0400 Date: Wed, 01 May 2019 20:48:41 +0300 Message-Id: <8336lyqd52.fsf@gnu.org> From: Eli Zaretskii To: Jonathan Tomer In-reply-to: (message from Jonathan Tomer on Tue, 30 Apr 2019 14:10:32 -0700) Subject: Re: bug#35497: [PATCH] Don't rewrite buffer contents after saving by rename References: <20190429232009.94549-1-jktomer@google.com> <87pnp4t0zp.fsf@gmx.de> <875zqvz0co.fsf@gmx.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 35497 Cc: 35497@debbugs.gnu.org, michael.albinus@gmx.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Jonathan Tomer > Date: Tue, 30 Apr 2019 14:10:32 -0700 > Cc: 35497@debbugs.gnu.org > > Btw, your new test in files-tests.el uses file notifications. Possible > of course. But wouldn't it be more robust to check the inode number of > the involved files, and how it changes, or not? See file-attributes how > to retrieve the inode number of a file. > > I thought about checking that the inode number changes, but that wouldn't have > caught this particular bug (where the file is renamed into place with the > correct contents, and then rewritten in place again); indeed, that doesn't > appear to be easily caught with any examination of the final state alone, > since what we're looking for is to prove the *absence* of any write that fails > to change the inode number. (Perhaps we could check that the modification time > of the file, after write, is *less* than its inode change time, proving that > there has been no ordinary write since the rename -- but in my experience, > inode timestamps are not actually more reliable than inotify, and in > particular this check is easily defeated by the mode-setting that happens > after the write is complete, requiring care to make sure that save-buffer will > not attempt to do so.) I suggest to make a step back and clearly define what you are trying to test. Is it that we don't rewrite the file after saving it, or is it some condition regarding the inodes of the original and the new file? These are two different things, and the second one is extremely platform-dependent (because inodes exist only in certain filesystems, and are emulated in others, and also because which notifications are generated in such complex situations is very hard to guess in advance). From debbugs-submit-bounces@debbugs.gnu.org Wed May 01 15:30:05 2019 Received: (at 35497) by debbugs.gnu.org; 1 May 2019 19:30:05 +0000 Received: from localhost ([127.0.0.1]:44959 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLuvc-0005Gf-2q for submit@debbugs.gnu.org; Wed, 01 May 2019 15:30:04 -0400 Received: from mail-ua1-f68.google.com ([209.85.222.68]:32921) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLuvZ-0005Ff-Rt for 35497@debbugs.gnu.org; Wed, 01 May 2019 15:30:03 -0400 Received: by mail-ua1-f68.google.com with SMTP id x6so3565306uaq.0 for <35497@debbugs.gnu.org>; Wed, 01 May 2019 12:30:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=d1ZmgSbT52gHmhuaJVJSC8wTcylervSTnpLPHOteAyc=; b=g7QOC62kZGlWUqDWIAi8EP+tIDFDilCCOlrULCneWmsdIPq71DvYkwyMQCAPHf3HER xIUsRMF4tYIGvMWF9ExOsQ1/Vhb/ZvAgBufaVlpoDeAofBaggud1Oe2lthQh+syYIPxo F9NxZNloOnweThvBYy0yFNGSdISX6kliE2juKC8KJc+eGPdmJ6Iy2Z7DNqnqxN2wGx6x R95y0nNnx500Gq7j9ql96Fqq6sJ43bSMs99xmW+0tI6eO1jFCQonhXwyKZDp2Ze9YS9b w0G+aCj5LYKKBSZrWAvotgSiLStd1WH6DWg2GR40rn0RzEW0Qm4hu8siwwAsJZuDHq/C 3oYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=d1ZmgSbT52gHmhuaJVJSC8wTcylervSTnpLPHOteAyc=; b=VeuWqaMOwsyB1lU+ovHShTvUtEiN0dQtxaGoLWYtlRgsZ2Kgf3HRKMh4MwK4YdEX90 Xk3tyjm+AnJUfjqfUd0luneYUzE1TN8Fzt0cScc9Ll7HtbqUq637amSd2MKsM5GK1Fy/ qA/SgB+vLI3Dc2hS8AeiKVP38vZvJX/orElg1YofWyIIbP2rAgTJMmhsqhIO0Q7syLTT iaW/9M4OLlLdDRm1xHkLEIGnIBo9OFaK5EQ87XghQbiJMU73O1ujlOgXVjuvp5lsEZEV Y2Jy8Kfnz/PcLkXwFLgM2Av8WSujkfntBkHe4qxR8QSAP59c2+nzgA/ckmezzY92qzD6 MN7g== X-Gm-Message-State: APjAAAVkaWpG92J+xxYiMjQ/N9e3bNf7D0blRvczuOCk3/aqglYQ66uu UiKvyu5dFkAZAP2PFRrRKR1GjgBE1eNEO12yVAzj6A== X-Google-Smtp-Source: APXvYqzVG9xuwRPQze2nXYnHp6tNR4jO98Ot9I6OpfV4+estIbwX/8v/fMd8R2d7xTsqMtXHRyHUWEgjZUl6m6NA4QE= X-Received: by 2002:ab0:2a13:: with SMTP id o19mr12067646uar.132.1556738994862; Wed, 01 May 2019 12:29:54 -0700 (PDT) MIME-Version: 1.0 References: <20190429232009.94549-1-jktomer@google.com> <87pnp4t0zp.fsf@gmx.de> <875zqvz0co.fsf@gmx.de> <8336lyqd52.fsf@gnu.org> In-Reply-To: <8336lyqd52.fsf@gnu.org> From: Jonathan Tomer Date: Wed, 1 May 2019 12:29:42 -0700 Message-ID: Subject: Re: bug#35497: [PATCH] Don't rewrite buffer contents after saving by rename To: Eli Zaretskii Content-Type: multipart/alternative; boundary="000000000000cc699c0587d88a9d" X-Spam-Score: -8.0 (--------) X-Debbugs-Envelope-To: 35497 Cc: 35497@debbugs.gnu.org, Michael Albinus X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -9.0 (---------) --000000000000cc699c0587d88a9d Content-Type: text/plain; charset="UTF-8" On Wed, May 1, 2019, 10:48 Eli Zaretskii wrote: > > From: Jonathan Tomer > > Date: Tue, 30 Apr 2019 14:10:32 -0700 > > Cc: 35497@debbugs.gnu.org > > > > Btw, your new test in files-tests.el uses file notifications. Possible > > of course. But wouldn't it be more robust to check the inode number of > > the involved files, and how it changes, or not? See file-attributes how > > to retrieve the inode number of a file. > > > > I thought about checking that the inode number changes, but that > wouldn't have > > caught this particular bug (where the file is renamed into place with the > > correct contents, and then rewritten in place again); indeed, that > doesn't > > appear to be easily caught with any examination of the final state alone, > > since what we're looking for is to prove the *absence* of any write that > fails > > to change the inode number. (Perhaps we could check that the > modification time > > of the file, after write, is *less* than its inode change time, proving > that > > there has been no ordinary write since the rename -- but in my > experience, > > inode timestamps are not actually more reliable than inotify, and in > > particular this check is easily defeated by the mode-setting that happens > > after the write is complete, requiring care to make sure that > save-buffer will > > not attempt to do so.) > > I suggest to make a step back and clearly define what you are trying > to test. Is it that we don't rewrite the file after saving it, or is > it some condition regarding the inodes of the original and the new > file? > > These are two different things, and the second one is extremely > platform-dependent (because inodes exist only in certain filesystems, > and are emulated in others, and also because which notifications are > generated in such complex situations is very hard to guess in > advance). > Indeed. What I am testing, as you say, is that the file is not changed by writing to it under its final name (ever, not just after renaming, though the latter happened to be the bug in this case) when file-precious-flag is non-nil. Any discussion of inodes was only because of the perceived unreliability, and actual relative unportability, of filenotify and the systems underlying it. It's true that notifications are imperfect, but IMO they are the only possible way to test that particular invariant, and this test implementation is designed to be as strict as the available notification system allows without breaking under any reasonable notification API. > --000000000000cc699c0587d88a9d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Wed, May 1, 2019, 10:48 Eli Zaretskii <eliz@gnu.org> wrote:
> From: Jonathan Tomer <jktomer@google.com><= br> > Date: Tue, 30 Apr 2019 14:10:32 -0700
> Cc: 35497@debbugs.gnu.org
>
>=C2=A0 Btw, your new test in files-tests.el uses file notifications. Po= ssible
>=C2=A0 of course. But wouldn't it be more robust to check the inode= number of
>=C2=A0 the involved files, and how it changes, or not? See file-attribu= tes how
>=C2=A0 to retrieve the inode number of a file.
>
> I thought about checking that the inode number changes, but that would= n't have
> caught this particular bug (where the file is renamed into place with = the
> correct contents, and then rewritten in place again); indeed, that doe= sn't
> appear to be easily caught with any examination of the final state alo= ne,
> since what we're looking for is to prove the *absence* of any writ= e that fails
> to change the inode number. (Perhaps we could check that the modificat= ion time
> of the file, after write, is *less* than its inode change time, provin= g that
> there has been no ordinary write since the rename -- but in my experie= nce,
> inode timestamps are not actually more reliable than inotify, and in > particular this check is easily defeated by the mode-setting that happ= ens
> after the write is complete, requiring care to make sure that save-buf= fer will
> not attempt to do so.)

I suggest to make a step back and clearly define what you are trying
to test.=C2=A0 Is it that we don't rewrite the file after saving it, or= is
it some condition regarding the inodes of the original and the new
file?

These are two different things, and the second one is extremely
platform-dependent (because inodes exist only in certain filesystems,
and are emulated in others, and also because which notifications are
generated in such complex situations is very hard to guess in
advance).

Indeed. What I am testing, as you say, is that the file is not ch= anged by writing to it under its final name (ever, not just after renaming,= though the latter happened to be the bug in this case) when file-precious-= flag is non-nil.

Any dis= cussion of inodes was only because of the perceived unreliability, and actu= al relative unportability, of filenotify and the systems underlying it.

It's true that notifica= tions are imperfect, but IMO they are the only possible way to test that pa= rticular invariant, and this test implementation is designed to be as stric= t as the available notification system allows without breaking under any re= asonable notification API.
--000000000000cc699c0587d88a9d-- From debbugs-submit-bounces@debbugs.gnu.org Wed May 01 15:55:25 2019 Received: (at 35497) by debbugs.gnu.org; 1 May 2019 19:55:25 +0000 Received: from localhost ([127.0.0.1]:44989 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLvK9-0005rm-1q for submit@debbugs.gnu.org; Wed, 01 May 2019 15:55:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58681) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLvK5-0005rY-UN for 35497@debbugs.gnu.org; Wed, 01 May 2019 15:55:22 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:59773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLvK0-0005ti-3C; Wed, 01 May 2019 15:55:16 -0400 Received: from [176.228.60.248] (port=1987 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hLvJt-00083B-TB; Wed, 01 May 2019 15:55:15 -0400 Date: Wed, 01 May 2019 22:54:49 +0300 Message-Id: <83tveeosqe.fsf@gnu.org> From: Eli Zaretskii To: Jonathan Tomer In-reply-to: (message from Jonathan Tomer on Wed, 1 May 2019 12:29:42 -0700) Subject: Re: bug#35497: [PATCH] Don't rewrite buffer contents after saving by rename References: <20190429232009.94549-1-jktomer@google.com> <87pnp4t0zp.fsf@gmx.de> <875zqvz0co.fsf@gmx.de> <8336lyqd52.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 35497 Cc: 35497@debbugs.gnu.org, michael.albinus@gmx.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Jonathan Tomer > Date: Wed, 1 May 2019 12:29:42 -0700 > Cc: Michael Albinus , 35497@debbugs.gnu.org > > It's true that notifications are imperfect, but IMO they are the only possible way to test that particular invariant, I'm not sure. You could instead advise or hook write-region, and see that it is not being called to write to the file, for example. Wouldn't that be easier and more reliable? From debbugs-submit-bounces@debbugs.gnu.org Wed May 01 15:56:53 2019 Received: (at 35497) by debbugs.gnu.org; 1 May 2019 19:56:53 +0000 Received: from localhost ([127.0.0.1]:44993 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLvLZ-0005tq-Et for submit@debbugs.gnu.org; Wed, 01 May 2019 15:56:53 -0400 Received: from mail-vs1-f51.google.com ([209.85.217.51]:36258) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLvLY-0005te-8i for 35497@debbugs.gnu.org; Wed, 01 May 2019 15:56:52 -0400 Received: by mail-vs1-f51.google.com with SMTP id x78so82223vsc.3 for <35497@debbugs.gnu.org>; Wed, 01 May 2019 12:56:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bSF+YoWXBuMaxuCy77i65pnvx6qg8xR21NmFCE2cJXw=; b=J2gLST9RvpxyBbhxeS91WsWzOOcdKEuo7USGS6djnMaDmMCu+KNtuY6hZKBPGRgaAV JP5CwsRBI5dK5jYMvuVXi5SI3nduyt8O/If3ZOH2Ih0+L/1uopw/JPEeDAVnMdAnFlxb 9deVshhsi5V0ujCT3h8qV6161lVU3ZJV4gKAAWFYrPkOzpq1jb3aW+UYUquqpABC2rOA irnSYuBmpnerrPuEDc3OKCfnmRkpEho99gbrGMwEIGqOHMxBPb6TR41ZtjuOav/nFBzx 6rE1X/TEtEhuhwzzc/M8x86dlrReQnpVKEqr2fPC/vOsDiQ6jqTbPzms6EcKSnO0QHXy cjAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bSF+YoWXBuMaxuCy77i65pnvx6qg8xR21NmFCE2cJXw=; b=YBCyj2s11eF8ELbTwNnZPap1zBijlceUNJG1j4PJ0lmWUjDm0pKGtvuaHYDXdY18oe 6/yYcjU/oGJfzIskYlsMSAOrA0KO1YRGxJa4TNbvPb1K8oyQMKChxcO8c1ZsZljr6Qjx 2JJNZY1EheOgTPDhrKsVlmP9QHXOgt1JAo9mkr/gDXjhPI/2yOCaQVuoIJZOkKxHOAqz nMQjIvn1Vj5mLw+t+vffmy+B7bYZFKrL3MWSWq1BEBMj6w8XSSms+lJxhEYdNIndJcGr e4OTiuEqilaOG/z+uFB5BnsP1QkYXuueFX4DFc+6MQQcAXhnKBp3J2WqGkMPbX/lplQA 9EmQ== X-Gm-Message-State: APjAAAUTn3LRnJ+AGskpGf+6eSCwRyHtmqA7uQtDZ8U1EPKGodQ6gwii 6ijDb9CRFQvIqLBqDNqL7I8oo69rbS2fgNocaabGsw== X-Google-Smtp-Source: APXvYqx0z4JXNXqoA19tKu7xR6W7lknss7EzGp0DxBdrwBSX6btpPGRSHUtQxWJ5hxe765On0/2ymwyCHh58qdg091U= X-Received: by 2002:a67:6852:: with SMTP id d79mr11927306vsc.80.1556740606028; Wed, 01 May 2019 12:56:46 -0700 (PDT) MIME-Version: 1.0 References: <20190429232009.94549-1-jktomer@google.com> <87pnp4t0zp.fsf@gmx.de> <875zqvz0co.fsf@gmx.de> <8336lyqd52.fsf@gnu.org> <83tveeosqe.fsf@gnu.org> In-Reply-To: <83tveeosqe.fsf@gnu.org> From: Jonathan Tomer Date: Wed, 1 May 2019 12:56:35 -0700 Message-ID: Subject: Re: bug#35497: [PATCH] Don't rewrite buffer contents after saving by rename To: Eli Zaretskii Content-Type: multipart/alternative; boundary="000000000000d505190587d8ea70" X-Spam-Score: -8.0 (--------) X-Debbugs-Envelope-To: 35497 Cc: 35497@debbugs.gnu.org, Michael Albinus X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -9.0 (---------) --000000000000d505190587d8ea70 Content-Type: text/plain; charset="UTF-8" On Wed, May 1, 2019 at 12:55 PM Eli Zaretskii wrote: > > From: Jonathan Tomer > > Date: Wed, 1 May 2019 12:29:42 -0700 > > Cc: Michael Albinus , 35497@debbugs.gnu.org > > > > It's true that notifications are imperfect, but IMO they are the only > possible way to test that particular invariant, > > I'm not sure. You could instead advise or hook write-region, and see > that it is not being called to write to the file, for example. > Wouldn't that be easier and more reliable? > Oh, of course -- that's quite a bit better. Thanks, will send a new patch in a moment. --000000000000d505190587d8ea70 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, May 1, 2019 at 12:55 PM Eli Zaret= skii <eliz@gnu.org> wrote:
> From: Jonathan Tomer <jktomer@google.com>
> Date: Wed, 1 May 2019 12:29:42 -0700
> Cc: Michael Albinus <michael.albinus@gmx.de>, 35497@debbu= gs.gnu.org
>
> It's true that notifications are imperfect, but IMO they are the o= nly possible way to test that particular invariant,

I'm not sure.=C2=A0 You could instead advise or hook write-region, and = see
that it is not being called to write to the file, for example.
Wouldn't that be easier and more reliable?

Oh, of course -- that's quite a bit better. Thanks, will send a= new patch in a moment.=C2=A0
--000000000000d505190587d8ea70-- From debbugs-submit-bounces@debbugs.gnu.org Wed May 01 19:03:21 2019 Received: (at 35497) by debbugs.gnu.org; 1 May 2019 23:03:21 +0000 Received: from localhost ([127.0.0.1]:45173 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLyG1-0003w8-Fn for submit@debbugs.gnu.org; Wed, 01 May 2019 19:03:21 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:35653) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <3sSXKXAcKBRI12B64w9y66y3w.u64LNMRPvwttCyA.y5C.69y@flex--jktomer.bounces.google.com>) id 1hLyG0-0003vu-36 for 35497@debbugs.gnu.org; Wed, 01 May 2019 19:03:20 -0400 Received: by mail-pf1-f202.google.com with SMTP id c12so215728pfb.2 for <35497@debbugs.gnu.org>; Wed, 01 May 2019 16:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=aVIyvkjVbA4nZTutMPnEMIqUhRpz8yoqfPi+yWC8FeE=; b=NCMv+puEoB6D6emJNwR1mV1kclEDnbJoGk9sPWLj2frOBQPeaxVll1mxk+HX3Hqg6E ftw+jjDzFDQWgxub/DS53WPIkpvAVZFFvqLf2Noof0DyzQESw3pcKNs3nqSokwoQAi6A +zKY7q8fmMyH/TWQA9YNvMWE76Z8KZZbv3CFIhTAzNew9+CUQNZi2SfTM8zvy7J3qlOO nxNJwXnDU6w1eiiixUebLiQcs4+UM8PA0Zg6mQylw0wPzNtkeHCxRa8pmTU7GZ86FGzL 1x09gQmmMHWAw9iMiqvezXYIOK/Z+DC6bak5Zb3kDD3G5hZgPqo1QO0kgc7km2S7QP0L YBIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=aVIyvkjVbA4nZTutMPnEMIqUhRpz8yoqfPi+yWC8FeE=; b=koNxin5g6uvkNMxnwJWMOghYYcYVxpJZNqGbxLwI5CWdpLcN6HWNlSGc6Z7oS5pNfe YUL+Ir8UTsEJURUNirz3m9cLvyO9/Zb0oSFOYsH3XS0A3KTJZqRBq/9EqOoma3Nzpb6P zsbeL2yN6+WTqe/3H2r8o9Nq7JIY+6U6IknqvparqCUGLE1XgnENkPH/nHPqo3X9oqpj eAaFDSxulsf+qXJW6Y5Q3Yq9a+iB60l6z8/FMXE+8NHLfQ+n2+ijImli9H16EtM5ZPPm vhDBmEgI3ZSsUPkfiqH+JLko4dsJDSHh4/3bZ04SCFhddTvkOFDdQowX0goJ95axA9cv V4pQ== X-Gm-Message-State: APjAAAWILCMxiZBs8RYuQcgh0+UKQjrf/RthNQ5qB1RNqhCvjJ8WZwi5 tJKZNbECPYdVPDEH6uQbHZwVUf4+YCfNqnbHH4bVO8vK0MFtiZPmTAAuLYH5CqJh/bP5f8pA3YM h7UYaZ9J/Y9NXrPFJ7eoY8nLJ2gqknfXXvfQI3DeZgThEpIiI1k67hPUv31jF32I= X-Google-Smtp-Source: APXvYqxAZK4ZY+8izXaFDmCJqEsGo1Yr249IapzezS/01AObMnv5nTzrQ8qlFsFnKcwGY89HZP5mZZS1HG2B X-Received: by 2002:a65:60d7:: with SMTP id r23mr531064pgv.223.1556751793511; Wed, 01 May 2019 16:03:13 -0700 (PDT) Date: Wed, 1 May 2019 16:02:01 -0700 In-Reply-To: <83tveeosqe.fsf@gnu.org> Message-Id: <20190501230200.46879-1-jktomer@google.com> Mime-Version: 1.0 References: <83tveeosqe.fsf@gnu.org> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog Subject: [PATCH v3] Don't rewrite buffer contents after saving by rename From: Jonathan Tomer To: 35497@debbugs.gnu.org, eliz@gnu.org, michael.albinus@gmx.de Content-Type: text/plain; charset="UTF-8" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 35497 Cc: Jonathan Tomer X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) When `file-precious-flag' is non-nil, files are saved by renaming a temporary file to the new name; this is an atomic operation on POSIX so other programs will not see the file in an intermediate state. Unfortunately, due to a paren-matching error introduced in change 574c05e219476912db3105fa164accd9ba12b35f, we would then write the contents again in the usual way after this rename. In addition to being wasteful, this is a serious bug: the whole point of `file-precious-flag' is to prevent race conditions with other programs that might otherwise see an empty file, but with this bug the race is actually much *more* likely to be visible: the rename will alert any inotify watchers of a change, and then the subsequent write is very likely to truncate the file just as those programs start to read it! * lisp/files.el (basic-save-buffer-2): Don't rewrite file contents after saving-by-renaming. * test/lisp/files-tests.el (files-tests-dont-rewrite-precious-files): * test/lisp/net/tramp-tests.el (tramp-test46-file-precious-flag): Regression tests for this change. --- lisp/files.el | 4 ++-- test/lisp/files-tests.el | 13 +++++++++++++ test/lisp/net/tramp-tests.el | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index c05d70a00e..72518e8127 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5256,7 +5256,7 @@ basic-save-buffer-2 (set-file-extended-attributes buffer-file-name (nth 1 setmodes))) (set-file-modes buffer-file-name - (logior (car setmodes) 128)))))) + (logior (car setmodes) 128))))) (let (success) (unwind-protect (progn @@ -5272,7 +5272,7 @@ basic-save-buffer-2 (and setmodes (not success) (progn (rename-file (nth 2 setmodes) buffer-file-name t) - (setq buffer-backed-up nil)))))) + (setq buffer-backed-up nil))))))) setmodes)) (declare-function diff-no-select "diff" diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index ae8ea41a79..0becde4184 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1244,5 +1244,18 @@ files-tests-file-attributes-equal (executable-find (file-name-nondirectory tmpfile)))))) (delete-file tmpfile)))) +(ert-deftest files-tests-dont-rewrite-precious-files () + "Test that `file-precious-flag' forces files to be saved by +renaming only, rather than modified in-place." + (files-tests--with-temp-file temp-file-name + (files-tests--with-advice + write-region :before + (lambda (_start _end filename &rest r) + (should (not (string= filename temp-file-name)))) + (with-current-buffer (find-file-noselect temp-file-name) + (setq-local file-precious-flag t) + (insert "foobar") + (should (null (save-buffer))))))) + (provide 'files-tests) ;;; files-tests.el ends here diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index cba697da18..03ce6a5e94 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -5741,6 +5741,22 @@ tramp--test-asynchronous-requests-timeout (ignore-errors (all-completions "tramp" (symbol-value x))) (ert-fail (format "Hook `%s' still contains Tramp function" x)))))) +(ert-deftest tramp-test46-file-precious-flag () + "Check that file-precious-flag is respected with Tramp in use." + (let* ((temp-file (make-temp-file "emacs")) + (remote-file (concat "/mock:localhost:" temp-file)) + (advice (lambda (_start _end filename &rest r) + (should (not (string= filename temp-file))) + (should (not (string= filename remote-file)))))) + (unwind-protect + (with-current-buffer (find-file-noselect remote-file) + (advice-add 'write-region :before advice) + (setq-local file-precious-flag t) + (insert "foobar") + (should (null (save-buffer)))) + (advice-remove 'write-region advice) + (delete-file temp-file)))) + (defun tramp-test-all (&optional interactive) "Run all tests for \\[tramp]." (interactive "p") -- 2.21.0.593.g511ec345e18-goog From debbugs-submit-bounces@debbugs.gnu.org Thu May 02 07:51:10 2019 Received: (at 35497) by debbugs.gnu.org; 2 May 2019 11:51:10 +0000 Received: from localhost ([127.0.0.1]:45720 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMAF4-0007Tw-HV for submit@debbugs.gnu.org; Thu, 02 May 2019 07:51:10 -0400 Received: from mout.gmx.net ([212.227.17.22]:46921) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMAEz-0007TP-F3 for 35497@debbugs.gnu.org; Thu, 02 May 2019 07:51:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1556797858; bh=yeZt8hS/cHjPAVvMRmo2T4/49lvt3IdbKcl5uRtSzV4=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=UvoZ/1kUi5Xm/V3+49Kc5vDvoNRWB3UV7nvDxb+AUcGGwOZAUDAarJ4g4ZUMwv3EZ Zm2H7gQcHbAf+eJu6R8pEpr77VNARNOctQg29AnbytrTsUVgiBqNbOTUg+a7zYLAx4 wJA071EGCw3t5U0YHzyuqhy7XOiegK+qiu8irpH4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from detlef.gmx.de ([212.86.60.150]) by mail.gmx.com (mrgmx103 [212.227.17.168]) with ESMTPSA (Nemesis) id 0Ltqmn-1gfNB640Kj-0119mH; Thu, 02 May 2019 13:50:58 +0200 From: Michael Albinus To: Jonathan Tomer Subject: Re: [PATCH v3] Don't rewrite buffer contents after saving by rename References: <83tveeosqe.fsf@gnu.org> <20190501230200.46879-1-jktomer@google.com> Date: Thu, 02 May 2019 13:50:56 +0200 In-Reply-To: <20190501230200.46879-1-jktomer@google.com> (Jonathan Tomer's message of "Wed, 1 May 2019 16:02:01 -0700") Message-ID: <87ftpx5b33.fsf@gmx.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:9UE0IB3igEM052i+lMOBpN7qPUlYcMdDwmz/jRZ600VY4wV2JZT bHd1sIzT5TfTU7d1BowRFFnlt6asfEIndcXvtNSGiLq1Hd+UFq9q0Acw6pB8d62Mu46n/y7 vWUOj/Rj1qmxbY4GOOPeXaUvhFxY7gKWcSFWgzAFmZiLtnq+KZ8NN9kaal9ep+dTIfSL4kf vD8Q0DjAFCxGqnX3IRcMA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:VFsPAvWwoRA=:c/Lds5Q0GRJlEmox7pSGVF fYHncSV3lR+AlxKix9zDFZUGJju15IgtLXiYL6X0QTbYEgmAfjy5Ey+k3b/JUSiZbx983SiOt e/eLIotgdrzxTCDEmp3in4t2HNnSR/CXqz9pE/bgit1QkuUPh2Gu6WiMsCWafth5tZMzFuNuZ EKwh3za6LVEuwVC57SIBygb3Ogrg20wMEh8+OzORoByc3mEE6SCgL1MBdHVVLnKd28DW2hgsT f6fJT0tKYGw5oNRtKALzdzPig4WW5he3bBqvYhIxAOu1U5kIptfH8tVxSgl0m6czgzFTmVNMy 0k+mBxl4mX0hRomnrUHovlnvzG4U5cGptpK0gdjJRBsfe9VJY/eEbI8I3Xto3by5GOAeH1PG3 8ScFEQtezYXfPY0pdo0IKMXDauOu50bWBOVGP+/CKrPDOsg8ovnytW/XgGOCY7uK7LTwYN5xr eULDpkMK5WWiHuZKUKB2d4K1vsslExRIY/Fs79NbcaEDk0qjSKYWpp+D9J5a1yh53SEp1kYAY 90P5qIfG5ZwrtbeCKFbP3HZ6KOV1/5evv+CW674Lvy+JBYDuzLFfjW2F673QegjAjG8jG45VO QXVXDe6ixvCbYK2PHx2BX5IUeNeWL9DzXeBh90ZVaTaLwbf+GXOhNQgqvdn2zW+5vjNvGDLlp vhXCAtNfFqTVZq57p3PRvU/RIa82AUb7jViSgG3EAaoIDGyfVytACJUtVXx2szU6c1PwlZLFz T67Q4pn2vmhuY7K3xO84vFnZcDDQwCan8S6lRvBNge7qwLOUfQ9Ieug39ThYSR3WpfyKJ19Z3 VwpcjsXStjdi7MHtSGzF00azNqzjScj4xRNJCM2S6dBuJGjJSaV3muVRkWJK9ArXUvEdXX90d jZRvjNQ3qzPkk9bnsmeQNK8DfUiMuRQA1LccAQMDug50D6uRf64KTd14gH+tcSl+m6FoRZlDL c+pYpA7vc1g== Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 35497 Cc: eliz@gnu.org, 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Jonathan Tomer writes: Hi Jonathan, > +(ert-deftest tramp-test46-file-precious-flag () Since this belongs rather to write-region, I would call it `tramp-test10-write-region-file-precious-flag', and move it to the repsective place in file. > + "Check that file-precious-flag is respected with Tramp in use." > + (let* ((temp-file (make-temp-file "emacs")) > + (remote-file (concat "/mock:localhost:" temp-file)) Please don't do this. The mock method does not work everywhere, for example on an MS Windows machine. `file-precious-flag' is handled in the tramp-sh.el handler only. So you might start with the test `tramp--test-sh-p', and skip otherwise. And then you could use the same mechanism like in the other tests. Something like this: =2D-8<---------------cut here---------------start------------->8--- (ert-deftest tramp-test10-write-region-file-precious-flag () "Check that `file-precious-flag' is respected with Tramp in use." (skip-unless (tramp--test-enabled)) (skip-unless (tramp--test-sh-p)) (let ((tmp-name (tramp--test-make-temp-name)) (advice (lambda (_start _end filename &rest r) (should-not (string=3D filename tmp-name))))) (unwind-protect (with-current-buffer (find-file-noselect tmp-name) ;; Write initial contents. Adapt `visited-file-modtime' ;; in order to suppress confirmation. (insert "foo") (write-region nil nil tmp-name) (set-visited-file-modtime) ;; Run the test. (advice-add 'write-region :before advice) (setq-local file-precious-flag t) (insert "bar") (should (null (save-buffer)))) ;; Cleanup. (ignore-errors (advice-remove 'write-region advice)) (ignore-errors (delete-file tmp-name))))) =2D-8<---------------cut here---------------end--------------->8--- I haven't tested further, this gives an error for me. Don't know yet, whether it is the test definition, or (more likely) a problem in Tramp. Best regards, Michael. From debbugs-submit-bounces@debbugs.gnu.org Thu May 02 18:04:22 2019 Received: (at 35497) by debbugs.gnu.org; 2 May 2019 22:04:22 +0000 Received: from localhost ([127.0.0.1]:47201 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMJoT-0001Sk-Ld for submit@debbugs.gnu.org; Thu, 02 May 2019 18:04:22 -0400 Received: from mail-vs1-f68.google.com ([209.85.217.68]:41254) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMJoR-0001SW-4O for 35497@debbugs.gnu.org; Thu, 02 May 2019 18:04:19 -0400 Received: by mail-vs1-f68.google.com with SMTP id g187so2355540vsc.8 for <35497@debbugs.gnu.org>; Thu, 02 May 2019 15:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ggXtjxw76o4SQzo3dIsSi0iNkUtrbNlQkIPkuc3gwTA=; b=i5PMz2UoL7fyWOsrOG3qk04NoR3fj/ABB1/2OWRUA4lxYv7eM13GLrD9ZvAo1getIx vJtMmWMQxHmwgMZ1OOws3k815/z1RNcpfFfSg4eiLiZawlrqfk1anPlDSdvToJj/R/La QpTykVlXiOxBVsIiyDJ8xo/r1+/ssq1djCG+sPgH6hJz9UUyMhphbIB6KkoKDl0GcMDJ TSUiv53xDhbHh7sCJlZ/3tCMF7NBa/ib5buOnT2j772bhcGFTPiGC2hLhjqrNqvwhtJI hlKZoUlDpJBZVP11RtmKZC6hZlIzaxun7GeJUvsNEaDkAEOHmXb++VFD0K2Ub8n342lx A1NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ggXtjxw76o4SQzo3dIsSi0iNkUtrbNlQkIPkuc3gwTA=; b=ITilGs+HM4kz9ns7f+zdzsWw5yFC283DWWera7s1sSeHFDHoDzsNjo/GnYu8rjilS+ R0FAa7J+4ymqjC4UM/mGy7d7+aZU5jcqvl7pkdUjPF84W3blw/blkZ/HfSQggY/GKiyl JAQTYDwnhbmhHBu8Ue0jaZgn6VB2E/8PouNOam0fsIFszjZQYrqnxUdopuSFVjCY309M p9ERf+jUcBFiZRVaqhm/mHTeN7JlaSPoRzMS6bvqGztYqtgRqt25gCbni2Rzlmj6N93v Xu45tR+BzmnLXpdLE6gvLq81ptY3qC8EXq6oTXGOLS9jv/+qvnm3ti+H5UqNNU3Igp7X H8Yg== X-Gm-Message-State: APjAAAUOEZ5lF5Y5N+V/CitxPRJ5XV9ysafaeSpMQoXNm0NIcPv32rnC eHNDwGHDDd3L2dAD19lfm6Dbq/aqs87D2TN/iGpnoA== X-Google-Smtp-Source: APXvYqw0wVnTxw393ilrX52ehib8Tb+z2yiRzwRYU8312kZRdxKX3cQoIREPiEp2MsS25n/Z63RuDpJTMzJbkrNmmEk= X-Received: by 2002:a67:7bd2:: with SMTP id w201mr3766101vsc.120.1556834652958; Thu, 02 May 2019 15:04:12 -0700 (PDT) MIME-Version: 1.0 References: <83tveeosqe.fsf@gnu.org> <20190501230200.46879-1-jktomer@google.com> <87ftpx5b33.fsf@gmx.de> In-Reply-To: <87ftpx5b33.fsf@gmx.de> From: Jonathan Tomer Date: Thu, 2 May 2019 15:04:02 -0700 Message-ID: Subject: Re: [PATCH v3] Don't rewrite buffer contents after saving by rename To: Michael Albinus Content-Type: multipart/alternative; boundary="000000000000770e350587eed0ff" X-Spam-Score: -8.0 (--------) X-Debbugs-Envelope-To: 35497 Cc: Eli Zaretskii , 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -9.0 (---------) --000000000000770e350587eed0ff Content-Type: text/plain; charset="UTF-8" On Thu, May 2, 2019 at 4:50 AM Michael Albinus wrote: > Jonathan Tomer writes: > > Hi Jonathan, > > > +(ert-deftest tramp-test46-file-precious-flag () > > Since this belongs rather to write-region, I would call it > `tramp-test10-write-region-file-precious-flag', and move it to the > repsective place in file. > > > + "Check that file-precious-flag is respected with Tramp in use." > > + (let* ((temp-file (make-temp-file "emacs")) > > + (remote-file (concat "/mock:localhost:" temp-file)) > > Please don't do this. The mock method does not work everywhere, for > example on an MS Windows machine. > > `file-precious-flag' is handled in the tramp-sh.el handler only. So you > might start with the test `tramp--test-sh-p', and skip otherwise. > > And then you could use the same mechanism like in the other > tests. Something like this: > > --8<---------------cut here---------------start------------->8--- > (ert-deftest tramp-test10-write-region-file-precious-flag () > "Check that `file-precious-flag' is respected with Tramp in use." > (skip-unless (tramp--test-enabled)) > (skip-unless (tramp--test-sh-p)) > > (let ((tmp-name (tramp--test-make-temp-name)) > (advice (lambda (_start _end filename &rest r) > (should-not (string= filename tmp-name))))) > > (unwind-protect > (with-current-buffer (find-file-noselect tmp-name) > ;; Write initial contents. Adapt `visited-file-modtime' > ;; in order to suppress confirmation. > (insert "foo") > (write-region nil nil tmp-name) > (set-visited-file-modtime) > ;; Run the test. > (advice-add 'write-region :before advice) > (setq-local file-precious-flag t) > (insert "bar") > (should (null (save-buffer)))) > > ;; Cleanup. > (ignore-errors (advice-remove 'write-region advice)) > (ignore-errors (delete-file tmp-name))))) > --8<---------------cut here---------------end--------------->8--- > > I haven't tested further, this gives an error for me. Don't know yet, > whether it is the test definition, or (more likely) a problem in Tramp. > Changing let to let* fixes the test. New patch incoming. > > Best regards, Michael. > --000000000000770e350587eed0ff Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, May 2, 2019 at 4:50 AM Michael Al= binus <michael.albinus@gmx.de> wrote:
Jonathan To= mer <jktomer@google.com> writes:

Hi Jonathan,

> +(ert-deftest tramp-test46-file-precious-flag ()

Since this belongs rather to write-region, I would call it
`tramp-test10-write-region-file-precious-flag', and move it to the
repsective place in file.

> +=C2=A0 "Check that file-precious-flag is respected with Tramp in= use."
> +=C2=A0 (let* ((temp-file (make-temp-file "emacs"))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(remote-file (concat "/mock:lo= calhost:" temp-file))

Please don't do this. The mock method does not work everywhere, for
example on an MS Windows machine.

`file-precious-flag' is handled in the tramp-sh.el handler only. So you=
might start with the test `tramp--test-sh-p', and skip otherwise.

And then you could use the same mechanism like in the other
tests. Something like this:

--8<---------------cut here---------------start------------->8---
(ert-deftest tramp-test10-write-region-file-precious-flag ()
=C2=A0 "Check that `file-precious-flag' is respected with Tramp in= use."
=C2=A0 (skip-unless (tramp--test-enabled))
=C2=A0 (skip-unless (tramp--test-sh-p))

=C2=A0 (let ((tmp-name (tramp--test-make-temp-name))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (advice (lambda (_start _end filename &rest= r)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (should-not = (string=3D filename tmp-name)))))

=C2=A0 =C2=A0 (unwind-protect
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (with-current-buffer (find-file-noselect tmp-na= me)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; Write initial contents.=C2=A0 Adapt `= visited-file-modtime'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; in order to suppress confirmation. =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (insert "foo")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (write-region nil nil tmp-name)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (set-visited-file-modtime)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; Run the test.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (advice-add 'write-region :before ad= vice)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq-local file-precious-flag t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (insert "bar")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (should (null (save-buffer))))

=C2=A0 =C2=A0 =C2=A0 ;; Cleanup.
=C2=A0 =C2=A0 =C2=A0 (ignore-errors (advice-remove 'write-region advice= ))
=C2=A0 =C2=A0 =C2=A0 (ignore-errors (delete-file tmp-name)))))
--8<---------------cut here---------------end--------------->8---

I haven't tested further, this gives an error for me. Don't know ye= t,
whether it is the test definition, or (more likely) a problem in Tramp.
=

Changing let to let* fixes the test. New p= atch incoming.
=C2=A0

Best regards, Michael.
--000000000000770e350587eed0ff-- From debbugs-submit-bounces@debbugs.gnu.org Thu May 02 18:07:25 2019 Received: (at 35497) by debbugs.gnu.org; 2 May 2019 22:07:25 +0000 Received: from localhost ([127.0.0.1]:47205 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMJrR-0001X9-Cn for submit@debbugs.gnu.org; Thu, 02 May 2019 18:07:25 -0400 Received: from mail-pl1-f201.google.com ([209.85.214.201]:42546) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <3FWrLXAcKBQQnoxsqivksskpi.gsq798DBhiffykw.kry.svk@flex--jktomer.bounces.google.com>) id 1hMJrQ-0001Wt-7Q for 35497@debbugs.gnu.org; Thu, 02 May 2019 18:07:24 -0400 Received: by mail-pl1-f201.google.com with SMTP id a97so1980775pla.9 for <35497@debbugs.gnu.org>; Thu, 02 May 2019 15:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=l62vLC4iUPGGvzZWT3hpknxXMreP0YjeUs2wiD9kZUg=; b=Gl02f0PfobooE41YKVrGmsRAouih10k94WXkaI9gWLirSlnJMpZjmAsoKyskDYJqcu MWpNMZtkXhoOIwIMUYwtY9A757coQ7L8rsFfxEP1lI/0cR8M8vE0Kdv0MZXEOnKfpoK4 FmySimZKmCRY+uKr3kVSiIOSvKJE+rNjVrhAiqfm3SUwvVo7zDI8zU419WIWLmqw4fVA txHvaU6c5bI2Rd9Hw3Dnu7syrNH3w5aqNBvfdc+d7vYdbUdu4WM47AHCzYcQOAb818s4 DA7gxbAnYz6SRtcV2E5qxbKPvDbZkJhiRyCsAV7NsK2OIlHJkPQinByCh9cVJWC7ZcM+ v+ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=l62vLC4iUPGGvzZWT3hpknxXMreP0YjeUs2wiD9kZUg=; b=JeIwX7sa4WAx/EExt1HXjKkUrH+HYvFqs6xf7o7g7EWhiVLnLBoWHtHWBaytBx0pfc jTvb4MAsjs2QXYVB67M92IlzcRyOZfhflNSN4ZjyI/2r8DoJ4FbaGQtGtHY8Fzm4T+r8 HvxeThgFa5tP82DTf+RjxIFbft+yImyZXqJztIikyPOeCQlEgm51ejbQGF4mGLpHmtrl N2n5ivWm7EOQ9W/kex8MRYP7806tmz719lchlP7Jiezyf0nPIKVjtn4x9WB3bOmr0Fcm 6OwpLVfl5wQKFBiLDukxdjPuePi3G9Ckga5tJplickbzs5m/L4iOJMMZFZmYYcvykVWm SMpQ== X-Gm-Message-State: APjAAAVDN3C8TomhuVKNqkzWjuJ6SeI+94d9r+1rMJ4yTAZWNH/BDGNh JXxh2bwgUdRgc13SiDsChSRevhIOPIFVvTcVAWN56TiJeesWw3kj3SZbImkEBnxT3grMZJhFITH g5Cio2ajVgSsRcKETv0z9dDafpnvXTnvKbmHZjQzd0ITx1Tu1ynJAlG4f/S9PEpc= X-Google-Smtp-Source: APXvYqywlb1rCO4zSK6opciM/DBtS7vPoKlc2NuSzV7/fTrKWRQFuP5g1dcs/+BHghk/W87a3WSiNbnDLZoS X-Received: by 2002:a63:8b4b:: with SMTP id j72mr6447650pge.318.1556834837767; Thu, 02 May 2019 15:07:17 -0700 (PDT) Date: Thu, 2 May 2019 15:06:50 -0700 In-Reply-To: <87ftpx5b33.fsf@gmx.de> Message-Id: <20190502220649.129146-1-jktomer@google.com> Mime-Version: 1.0 References: <87ftpx5b33.fsf@gmx.de> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog Subject: [PATCH v4] Don't rewrite buffer contents after saving by rename From: Jonathan Tomer To: 35497@debbugs.gnu.org, eliz@gnu.org, michael.albinus@gmx.de Content-Type: text/plain; charset="UTF-8" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 35497 Cc: Jonathan Tomer X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) When `file-precious-flag' is non-nil, files are saved by renaming a temporary file to the new name; this is an atomic operation on POSIX so other programs will not see the file in an intermediate state. Unfortunately, due to a paren-matching error introduced in change 574c05e219476912db3105fa164accd9ba12b35f, we would then write the contents again in the usual way after this rename. In addition to being wasteful, this is a serious bug: the whole point of `file-precious-flag' is to prevent race conditions with other programs that might otherwise see an empty file, but with this bug the race is actually much *more* likely to be visible: the rename will alert any inotify watchers of a change, and then the subsequent write is very likely to truncate the file just as those programs start to read it! * lisp/files.el (basic-save-buffer-2): Don't rewrite file contents after saving-by-renaming. * test/lisp/files-tests.el (files-tests-dont-rewrite-precious-files): * test/lisp/net/tramp-tests.el (tramp-test10-write-region-file-precious-flag): Regression tests for this change. --- lisp/files.el | 4 ++-- test/lisp/files-tests.el | 13 +++++++++++++ test/lisp/net/tramp-tests.el | 26 ++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index c05d70a00e..72518e8127 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5256,7 +5256,7 @@ basic-save-buffer-2 (set-file-extended-attributes buffer-file-name (nth 1 setmodes))) (set-file-modes buffer-file-name - (logior (car setmodes) 128)))))) + (logior (car setmodes) 128))))) (let (success) (unwind-protect (progn @@ -5272,7 +5272,7 @@ basic-save-buffer-2 (and setmodes (not success) (progn (rename-file (nth 2 setmodes) buffer-file-name t) - (setq buffer-backed-up nil)))))) + (setq buffer-backed-up nil))))))) setmodes)) (declare-function diff-no-select "diff" diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index ae8ea41a79..0becde4184 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1244,5 +1244,18 @@ files-tests-file-attributes-equal (executable-find (file-name-nondirectory tmpfile)))))) (delete-file tmpfile)))) +(ert-deftest files-tests-dont-rewrite-precious-files () + "Test that `file-precious-flag' forces files to be saved by +renaming only, rather than modified in-place." + (files-tests--with-temp-file temp-file-name + (files-tests--with-advice + write-region :before + (lambda (_start _end filename &rest r) + (should (not (string= filename temp-file-name)))) + (with-current-buffer (find-file-noselect temp-file-name) + (setq-local file-precious-flag t) + (insert "foobar") + (should (null (save-buffer))))))) + (provide 'files-tests) ;;; files-tests.el ends here diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index cba697da18..dee5e5e0f9 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -2270,6 +2270,32 @@ tramp--test-print-duration ;; Cleanup. (ignore-errors (delete-file tmp-name)))))) +(ert-deftest tramp-test10-write-region-file-precious-flag () + "Check that `file-precious-flag' is respected with Tramp in use." + (skip-unless (tramp--test-enabled)) + (skip-unless (tramp--test-sh-p)) + + (let* ((tmp-name (tramp--test-make-temp-name)) + (advice (lambda (_start _end filename &rest r) + (should-not (string= filename tmp-name))))) + + (unwind-protect + (with-current-buffer (find-file-noselect tmp-name) + ;; Write initial contents. Adapt `visited-file-modtime' + ;; in order to suppress confirmation. + (insert "foo") + (write-region nil nil tmp-name) + (set-visited-file-modtime) + ;; Run the test. + (advice-add 'write-region :before advice) + (setq-local file-precious-flag t) + (insert "bar") + (should (null (save-buffer)))) + + ;; Cleanup. + (ignore-errors (advice-remove 'write-region advice)) + (ignore-errors (delete-file tmp-name))))) + (ert-deftest tramp-test11-copy-file () "Check `copy-file'." (skip-unless (tramp--test-enabled)) -- 2.21.0.593.g511ec345e18-goog From debbugs-submit-bounces@debbugs.gnu.org Fri May 03 03:52:28 2019 Received: (at 35497) by debbugs.gnu.org; 3 May 2019 07:52:28 +0000 Received: from localhost ([127.0.0.1]:47619 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMSzc-0000YC-8u for submit@debbugs.gnu.org; Fri, 03 May 2019 03:52:28 -0400 Received: from mout.gmx.net ([212.227.17.22]:53999) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMSzZ-0000Xz-Qo for 35497@debbugs.gnu.org; Fri, 03 May 2019 03:52:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1556869937; bh=gva+ibIrRpNrAF7r80V6GKQfNoO0TOY3SDesyZj7Rs0=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date; b=CN8S/m2qaw/dXsROmdckUA7oNv4uAjEpOaLaHbk3mXFUniEb4XXam4hebnXGpm04Q n1oyPF1+TAmTcpO24zNj6phsXsvpaSIFecqR0Kum2CnskLYr6uJsbd5yP7mabftzYM lZc1fO5SXKRWhbBmelxChOOpP3e41B6rZswHUPIs= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from detlef.gmx.de ([213.220.157.162]) by mail.gmx.com (mrgmx103 [212.227.17.168]) with ESMTPSA (Nemesis) id 0LymjL-1git7P3SyN-0167mq; Fri, 03 May 2019 09:52:16 +0200 From: Michael Albinus To: Jonathan Tomer Subject: Re: [PATCH v4] Don't rewrite buffer contents after saving by rename References: <87ftpx5b33.fsf@gmx.de> <20190502220649.129146-1-jktomer@google.com> Date: Fri, 03 May 2019 09:52:13 +0200 Message-ID: <87o94k7z6a.fsf@gmx.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:rg85MbgcTxZBZvwongPK390jFX9tHz9cFxCR2ifAlnduBIwdp8S k3I/bzyk90me9+fh3owBPQsRPt51LKWAWtmXuZbe6p4qCOsezAM1Oe+dqSJU9aDd2WvCBdb 8h9iZIkKBExMRLxFpHhWU5MQdX2FZxOM7m0UkoAfauKR2Q/4kxbraw+boW+T1BEN1gp+Cdw 6V+39OSdzThLp28QWzopw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:FDQC8TkPcSs=:bNvd33VMfMPjrU8ohjqTE9 1hhiti/aRuuqUOtAiM5E9h11LeMP94V4yYr37Kir2ZHZghZvA/xu6ZeV2rRsLD1OgbO8iCQsC jUpXIhcVj3h1TOhnZt63sxvpQFae5qiZfZxAmF+54B4p5G4B2KRSUbczyqt55jYEjdG7uu30U 8IiYr7ptra/9dm4hZ5NY2G6NUwJ8tamBSjBcyok2crNg8DbyzI8HO0j3kFnjUq7Bgm7J1n0dO ooteZl6EiW5T4qWsKpqjmPYNcxTOisHmoSNRKYHrySWhv0eSMl7kXj/4CRlD23XWa9M60tCLr W2FLDGIcXU3eXGS5D9FeTRnGbU3YImUPnDwIZ+PRXNgNSil7ytH1fLQCMuEEB6lN9z30hXrqN qLUywLufebxfrD+bR1eaQBwZufLM87O5KEJuMeNGaKPn66UucOgJyAvAFaZuJwhh37Qi89cro feE82ZmQzvmbdisaqqPIsMHaW+dYcZ8hUBR435VkuE4nTnKUTHxW7MncRAFKcTeo2Z3sYEsMg TbKwYH43rxb5RQ8W/BAx4LhWydf7VMy2UX6sO+TJaXWc9IgLI8Bjzn8viLiVe0SGGlTqjvtaH bmOBsH4zmyBmxuKYZFKNrNfeUDER4EkE6T6g5FU63ARfeWibk6pQ8TX/YYbJzbKm8Iw88fTmG RE8m0s9VgT14uUL8NW/A4fAUGbEFMKNq73Qj+lgKkILxkgSsw1gJAnIxGRXDs+GuZawC4wUPo fw1Bniz/w2IjuOFQAbKVpHtKSa//ashxUf+JCpaTLvA0PzQ4LcL4hHLzRG3KSraMGS+3emSNh iMK76qYpMNife4VHSbhvslQNeXV3sf73aJRWEf+hseS9sHg6avnKk4vkUju0Z7ytu55/IImao zAatauvz3LVCDyKiI3vMf7xvyqvDEclQ8H4yPFKGVuy2FaF9UMUojc+OfRua/A7vxAKmrYbnc jZCZwH4ZpOQ== X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 35497 Cc: eliz@gnu.org, 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Jonathan Tomer writes: Hi Jonathan, I still get an error with the Tramp test: --8<---------------cut here---------------start------------->8--- Test tramp-test10-write-region-file-precious-flag condition: (file-error "Copying directly failed, see buffer `*tramp/mock detlef*' for details.") FAILED 2/2 tramp-test10-write-region-file-precious-flag (0.995086 sec) --8<---------------cut here---------------end--------------->8--- You might keep it as it is, but mark it unstable: > +(ert-deftest tramp-test10-write-region-file-precious-flag () > + "Check that `file-precious-flag' is respected with Tramp in use." > + :tags '(:unstable) I will check then what's up. Looks to me like you haven't signed yet the FSF papers. This is necessary to contribute to Emacs. Are you willing to sign them? You could read about this at . Best regards, Michael. From debbugs-submit-bounces@debbugs.gnu.org Fri May 03 08:29:51 2019 Received: (at 35497) by debbugs.gnu.org; 3 May 2019 12:29:52 +0000 Received: from localhost ([127.0.0.1]:47989 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMXK3-00053x-Jc for submit@debbugs.gnu.org; Fri, 03 May 2019 08:29:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34437) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMXK1-00053j-Vh for 35497@debbugs.gnu.org; Fri, 03 May 2019 08:29:50 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46841) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMXJw-0004NB-L9; Fri, 03 May 2019 08:29:44 -0400 Received: from [176.228.60.248] (port=4349 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hMXJw-00023m-02; Fri, 03 May 2019 08:29:44 -0400 Date: Fri, 03 May 2019 15:29:25 +0300 Message-Id: <83woj7n2l6.fsf@gnu.org> From: Eli Zaretskii To: Michael Albinus In-reply-to: <87o94k7z6a.fsf@gmx.de> (message from Michael Albinus on Fri, 03 May 2019 09:52:13 +0200) Subject: Re: [PATCH v4] Don't rewrite buffer contents after saving by rename References: <87ftpx5b33.fsf@gmx.de> <20190502220649.129146-1-jktomer@google.com> <87o94k7z6a.fsf@gmx.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 35497 Cc: jktomer@google.com, 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Michael Albinus > Cc: 35497@debbugs.gnu.org, eliz@gnu.org > Date: Fri, 03 May 2019 09:52:13 +0200 > > Looks to me like you haven't signed yet the FSF papers. This is > necessary to contribute to Emacs. Are you willing to sign them? You > could read about this at . He's @google.com, so if this work was done on Google's time, it's covered by Google's assignment. From debbugs-submit-bounces@debbugs.gnu.org Mon May 06 16:45:44 2019 Received: (at 35497) by debbugs.gnu.org; 6 May 2019 20:45:44 +0000 Received: from localhost ([127.0.0.1]:57579 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNkUZ-0001Zl-Ss for submit@debbugs.gnu.org; Mon, 06 May 2019 16:45:44 -0400 Received: from mail-vk1-f196.google.com ([209.85.221.196]:44775) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNkUY-0001ZX-5I for 35497@debbugs.gnu.org; Mon, 06 May 2019 16:45:42 -0400 Received: by mail-vk1-f196.google.com with SMTP id q189so3496379vkq.11 for <35497@debbugs.gnu.org>; Mon, 06 May 2019 13:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gIlw+900G2xnt/AQTvCaK60VnPgWsxfLotLgniDWMxE=; b=S4Mgj80Mv8wy+Q89+e2xRGZFxNr5ofkTvvq4PTW+zMTts95cK3HkdXrc0mP3oUCrAC 0jyKUbxioqI4OiZij+VsnK+iKKpvj1ZX8Zo12e7okWlwBcllBqVN2jMuy4FAtWIUmWK+ OO1fXdPyXagy3MoqB+NDZxaazlsJrwkRi7lF1zzxxupasjOs8uvg2emGeuJC32OZT1SR dTsjAKC3nBkXPnw+SHrXYwpv7C31FEZOJLRFheCsyqq3BwCjYT53SLvbNNK2a3cfvSyT LeM5zQt4XoQaOv7pWVOXNys2Y1aZ9EMi44yUjTVyIR7VR5LFxv4lSDRPFtGC265ub5Ec 6kDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gIlw+900G2xnt/AQTvCaK60VnPgWsxfLotLgniDWMxE=; b=loA9HARBiaTWY4us4+Db20hLhJRFvrk1BmZz0//unfz2+oB/ZHUcyzju+kqgEP/RAA u8IgbIptOGCUxASlzGKlcjCEV7twY6XJwLuR4JcsBEl5Ozi8JxEPk0Ja/g52wHbpt/CF g0jmaQ/W/3Y4HAASvboa8CX/K5NoknAWqK0R+mh+y11t6xbM1bWqJmZLZCOk/azlExAi 00SkPVAQ12QrMW9NaLc+4faVR1fSosIy7YeuZ2A+NWxpToPwYKbKnecBPzDqGB9AHaiM +rDYfVw/Xssrg2KDGJQHWQSKd/pcAnB+QL9yXkzBEpTjbk/Yif+60ixf5EBhm/2recqn R/QQ== X-Gm-Message-State: APjAAAXqOBhKfVwIIDOCpfLlHkttXrX0NBCXQaCkrE8fiES2memm9v2J 0s4HXxq0JvkoRv9VNUBmyAbyCcQKYSCBPsBLDrdACA== X-Google-Smtp-Source: APXvYqw/2M3KaffOPREBRR48fmB3iPyIy4+XLRzPjgA0MMJdSZaJI1NaFEfEwkSrPUrVT3NXpoW+8HqpQ2ZryxW28C0= X-Received: by 2002:a1f:c088:: with SMTP id q130mr2882948vkf.67.1557175535867; Mon, 06 May 2019 13:45:35 -0700 (PDT) MIME-Version: 1.0 References: <87ftpx5b33.fsf@gmx.de> <20190502220649.129146-1-jktomer@google.com> <87o94k7z6a.fsf@gmx.de> In-Reply-To: <87o94k7z6a.fsf@gmx.de> From: Jonathan Tomer Date: Mon, 6 May 2019 13:45:24 -0700 Message-ID: Subject: Re: [PATCH v4] Don't rewrite buffer contents after saving by rename To: Michael Albinus Content-Type: multipart/alternative; boundary="000000000000abea6105883e2e19" X-Spam-Score: -8.0 (--------) X-Debbugs-Envelope-To: 35497 Cc: Eli Zaretskii , 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -9.0 (---------) --000000000000abea6105883e2e19 Content-Type: text/plain; charset="UTF-8" On Fri, May 3, 2019 at 12:52 AM Michael Albinus wrote: > Jonathan Tomer writes: > > Hi Jonathan, > > I still get an error with the Tramp test: > > --8<---------------cut here---------------start------------->8--- > Test tramp-test10-write-region-file-precious-flag condition: > (file-error "Copying directly failed, see buffer `*tramp/mock detlef*' > for details.") > FAILED 2/2 tramp-test10-write-region-file-precious-flag (0.995086 sec) > --8<---------------cut here---------------end--------------->8--- > This is the form of the errors I get when the test fails intentionally (i.e. because I un-fix the bug and re-run the test). I've rewritten the test to fail properly when it's supposed to, but also left the unstable tag on it. > You might keep it as it is, but mark it unstable: > > > +(ert-deftest tramp-test10-write-region-file-precious-flag () > > + "Check that `file-precious-flag' is respected with Tramp in use." > > + :tags '(:unstable) > > I will check then what's up. > > Looks to me like you haven't signed yet the FSF papers. This is > necessary to contribute to Emacs. Are you willing to sign them? You > could read about this at < > https://www.gnu.org/prep/maintain/html_node/Copyright-Papers.html>. > As eliz@ notes, I cannot sign the personal form of the copyright assignment while I work for Google, since I have no copyright to assign, but Google's assignment should suffice. > > Best regards, Michael. > --000000000000abea6105883e2e19 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, May 3, 2019 at 12:52 AM Michael A= lbinus <michael.albinus@gmx.de= > wrote:
Jonathan Tomer <jktomer@google.com> writ= es:

Hi Jonathan,

I still get an error with the Tramp test:

--8<---------------cut here---------------start------------->8---
Test tramp-test10-write-region-file-precious-flag condition:
=C2=A0 =C2=A0 (file-error "Copying directly failed, see buffer `*tramp= /mock detlef*' for details.")
=C2=A0 =C2=A0FAILED=C2=A0 2/2=C2=A0 tramp-test10-write-region-file-precious= -flag (0.995086 sec)
--8<---------------cut here---------------end--------------->8---
=

This is the form of the errors I get when = the test fails intentionally (i.e. because I un-fix the bug and re-run the = test). I've rewritten the test to fail properly when it's supposed = to, but also left the unstable tag on it.
=C2=A0
You might keep it as it is, but mark= it unstable:

> +(ert-deftest tramp-test10-write-region-file-precious-flag ()
> +=C2=A0 "Check that `file-precious-flag' is respected with Tr= amp in use."
> +=C2=A0 :tags '(:unstable)

I will check then what's up.

Looks to me like you haven't signed yet the FSF papers. This is
necessary to contribute to Emacs. Are you willing to sign them? You
could read about this at <https://www.gnu.org/prep/maintain/html_node/Copyright-Papers.ht= ml>.

As eliz@ notes, I cannot=C2= =A0sign the personal form of the copyright assignment while I work for Goog= le, since I have no copyright to assign, but Google's assignment should= suffice.
=C2=A0

Best regards, Michael.
--000000000000abea6105883e2e19-- From debbugs-submit-bounces@debbugs.gnu.org Mon May 06 16:47:33 2019 Received: (at 35497) by debbugs.gnu.org; 6 May 2019 20:47:33 +0000 Received: from localhost ([127.0.0.1]:57583 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNkWL-0001dC-CB for submit@debbugs.gnu.org; Mon, 06 May 2019 16:47:33 -0400 Received: from mail-qt1-f202.google.com ([209.85.160.202]:34535) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <3Wp3QXAcKBcMst2xvn0pxxpun.lxvCEDIGmnkk3p1.pw3.x0p@flex--jktomer.bounces.google.com>) id 1hNkWJ-0001cy-HB for 35497@debbugs.gnu.org; Mon, 06 May 2019 16:47:32 -0400 Received: by mail-qt1-f202.google.com with SMTP id l10so10838888qtr.1 for <35497@debbugs.gnu.org>; Mon, 06 May 2019 13:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=lLsbgx11+DiKIav1JSgqtN4a6Ys+5MbKJTSM+fOfgeg=; b=miy1BLujSmfTpvVbcD1tQuaRt2Ytw4awx3q2HoqQqP9uBDDSvSSZtMSHrOBWb6g7BD 5xJ4AHCEtoikj948OJdXDxMV94WrS3ihG6xv8fJACuVVSrwEHmknpT0JXCzvUGZ9z4lQ rL82AiEPgxlm7ogx8LK5K9Xb3pExoE8qYuaiCPZ26z3yKc9tCUWjqrr2NGKHPIzjKtpF 2jtEC6fs5gKpvcuHzN4NqfpyHL86NlPF8ynKLbwbK2DCCVrZmTTEu3aB5J2yV6N35g0H spR9uQnaMlgDoV4kVRZbw3fRtgN02ZG5IAylpb2TLy9rNHlE4/q3uJm/9SOUqT/MDwa+ KC4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=lLsbgx11+DiKIav1JSgqtN4a6Ys+5MbKJTSM+fOfgeg=; b=lxe0IHY7dabyF7BnsPOxl4CEi7VJqIy9Qw6pba7CYQoUrU0r6rQH9q2nIaoc5W6iYK /FG8ocR2AWt/H3EE53mxaFfMzvWH+hnrw/tko7Fuef63ZAR9E7uAvkOTEy0e548hazVV GGmsXMGVvcegl0UjfDt7Xcp4HEzOgW5n0hAiQaZmPtAj0h578y+jcssQ9jLtk5W0B8yF IvfGI7teFUyQH1mx2a5furV9KR6GIxaO1gY7SIC7hk2SfMN76gMX0i162a1vZQzbPBeX GQl/evLm62573MR+BsVyy5Aa8oZX58LwwqbbSMUQDqpBCmn9iJ3AYfsMaWtuciRiEw4i wfOg== X-Gm-Message-State: APjAAAVDV65tzyaO9K+hGALXZJybc/QMMxLlGRaSg/4VSnH/k8043U6P 15Dgesub2hcLNrfQ16q6M3KEzcJoF9+4I7tmrIfLcWHOgqux9irOW09ikwZUGyuddBt01XyYeme a4W9WGYk0FhihlcddyEPxe7wb0f8BbKP5j2kT/adr0SGZ1wkcmFc2iOA+VJTBRWI= X-Google-Smtp-Source: APXvYqw/i3LiyHyP+lOqYx2IRxoO25UmqX8/IkTLHSQ80xTedIgk+/hv3yp11bh+SKc0DA+Ksq9Dm9EzVLyS X-Received: by 2002:a0c:b99c:: with SMTP id v28mr22653409qvf.10.1557175642693; Mon, 06 May 2019 13:47:22 -0700 (PDT) Date: Mon, 6 May 2019 13:46:07 -0700 In-Reply-To: <87o94k7z6a.fsf@gmx.de> Message-Id: <20190506204605.158797-1-jktomer@google.com> Mime-Version: 1.0 References: <87o94k7z6a.fsf@gmx.de> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog Subject: [PATCH v5] Don't rewrite buffer contents after saving by rename From: Jonathan Tomer To: 35497@debbugs.gnu.org, eliz@gnu.org, michael.albinus@gmx.de Content-Type: text/plain; charset="UTF-8" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 35497 Cc: Jonathan Tomer X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) When `file-precious-flag' is non-nil, files are saved by renaming a temporary file to the new name; this is an atomic operation on POSIX so other programs will not see the file in an intermediate state. Unfortunately, due to a paren-matching error introduced in change 574c05e219476912db3105fa164accd9ba12b35f, we would then write the contents again in the usual way after this rename. In addition to being wasteful, this is a serious bug: the whole point of `file-precious-flag' is to prevent race conditions with other programs that might otherwise see an empty file, but with this bug the race is actually much *more* likely to be visible: the rename will alert any inotify watchers of a change, and then the subsequent write is very likely to truncate the file just as those programs start to read it! * lisp/files.el (basic-save-buffer-2): Don't rewrite file contents after saving-by-renaming. * test/lisp/files-tests.el (files-tests-dont-rewrite-precious-files): * test/lisp/net/tramp-tests.el (tramp-test10-write-region-file-precious-flag): Regression tests for this change. --- lisp/files.el | 4 ++-- test/lisp/files-tests.el | 15 +++++++++++++++ test/lisp/net/tramp-tests.el | 27 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index c05d70a00e..72518e8127 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5256,7 +5256,7 @@ basic-save-buffer-2 (set-file-extended-attributes buffer-file-name (nth 1 setmodes))) (set-file-modes buffer-file-name - (logior (car setmodes) 128)))))) + (logior (car setmodes) 128))))) (let (success) (unwind-protect (progn @@ -5272,7 +5272,7 @@ basic-save-buffer-2 (and setmodes (not success) (progn (rename-file (nth 2 setmodes) buffer-file-name t) - (setq buffer-backed-up nil)))))) + (setq buffer-backed-up nil))))))) setmodes)) (declare-function diff-no-select "diff" diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index ae8ea41a79..fe2e958f1c 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1244,5 +1244,20 @@ files-tests-file-attributes-equal (executable-find (file-name-nondirectory tmpfile)))))) (delete-file tmpfile)))) +(ert-deftest files-tests-dont-rewrite-precious-files () + "Test that `file-precious-flag' forces files to be saved by +renaming only, rather than modified in-place." + (let* ((temp-file-name (make-temp-file "files-tests")) + (advice (lambda (_start _end filename &rest _r) + (should-not (string= filename temp-file-name))))) + (unwind-protect + (with-current-buffer (find-file-noselect temp-file-name) + (advice-add #'write-region :before advice) + (setq-local file-precious-flag t) + (insert "foobar") + (should (null (save-buffer)))) + (ignore-errors (advice-remove #'write-region advice)) + (ignore-errors (delete-file temp-file-name))))) + (provide 'files-tests) ;;; files-tests.el ends here diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index cba697da18..a18cb19c68 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -2270,6 +2270,33 @@ tramp--test-print-duration ;; Cleanup. (ignore-errors (delete-file tmp-name)))))) +(ert-deftest tramp-test10-write-region-file-precious-flag () + "Check that `file-precious-flag' is respected with Tramp in use." + :tags '(:unstable) + (skip-unless (tramp--test-enabled)) + (skip-unless (tramp--test-sh-p)) + + (let* ((tmp-name (tramp--test-make-temp-name)) + (advice (lambda (_start _end filename &rest _r) + (should-not (string= filename tmp-name))))) + + (unwind-protect + (with-current-buffer (find-file-noselect tmp-name) + ;; Write initial contents. Adapt `visited-file-modtime' + ;; in order to suppress confirmation. + (insert "foo") + (write-region nil nil tmp-name) + (set-visited-file-modtime) + ;; Run the test. + (advice-add 'write-region :before advice) + (setq-local file-precious-flag t) + (insert "bar") + (should (null (save-buffer)))) + + ;; Cleanup. + (ignore-errors (advice-remove 'write-region advice)) + (ignore-errors (delete-file tmp-name))))) + (ert-deftest tramp-test11-copy-file () "Check `copy-file'." (skip-unless (tramp--test-enabled)) -- 2.21.0.1020.gf2820cf01a-goog From debbugs-submit-bounces@debbugs.gnu.org Mon May 06 16:48:38 2019 Received: (at 35497) by debbugs.gnu.org; 6 May 2019 20:48:38 +0000 Received: from localhost ([127.0.0.1]:57587 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNkXN-0001fC-U2 for submit@debbugs.gnu.org; Mon, 06 May 2019 16:48:38 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:36365) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <3np3QXAcKBQkst2xvn0pxxpun.lxvCEDIGmnkk3p1.pw3.x0p@flex--jktomer.bounces.google.com>) id 1hNkXM-0001ew-8k for 35497@debbugs.gnu.org; Mon, 06 May 2019 16:48:36 -0400 Received: by mail-qk1-f201.google.com with SMTP id a12so15839879qkb.3 for <35497@debbugs.gnu.org>; Mon, 06 May 2019 13:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=VWAw4AX8zjCR3c5MPT2KcwH0H3g+QniPHj8XxrefbME=; b=JibbSvOwloNFGZ4T7yTkTuGfJ2+woPjD8VNaovws3s4ytjNS/kELMCCDb9NxSa/29e zexVwhMAfEzJGo2ipAdNT2ylUK1nVQhcCltP7taifJPFUUQufeNzMipN0DUj/pztXDJA FZ3yq5UBWhHQjMHrPzhZy9tmFpCcjSG6bzqukshu4LDllBRsSn0J+vQHlQNRmHV5Uvhd lly80IykK6SHq0FhM47cjGdasSiU5nC80NIUGJvbLPoIDf18IGpucueOJ/M2+LTUSTwr 98U9U+h74x2zgcjVEAyrFYbwC784nZO+6sZxYt30qvXIHWNyuOHz4w6vfkP/BkW1DlS6 kiuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=VWAw4AX8zjCR3c5MPT2KcwH0H3g+QniPHj8XxrefbME=; b=MiIjNhV6aFz5MT1l5ewyusZ7VvoCwamVUT8Bbpu7rnCUsyUtbtMY1c36E1hKFFlflD cENI068ij2w2+TE9KgtE6RRE8O9RFr/joKFW0AEtN3Ng7wfElKIS9M6+03NmOcExue71 T12ptJLDYd9+P0xg1RncpYpa5N63v0Vu8uNrlB+gueZqMfbSMKBQhiCw/S4J0VwT1chl Wa6LtN2nTgcjx+KXJw2zoidG+4ziTn/b2DyDey8A18xdCyb4oSA5neW+OFTfBWP3zb+l c56VwMPO2gFFvY0UmkQJhkB6pq6Ggj2yo5fmmDOVSGQ8Kv2EhgM0d6Q79CcdcEwC6F2L yjuA== X-Gm-Message-State: APjAAAUPHAGM2mUIWdW//507PGUclikyzeYU2kumv+ZNIknsIiElZ5n2 pZmqyBxNi99UtXqZCG7nTwOU9ynhH39puRMT++NcmFFJxTo1qtfEC87FOjr4mbUOyy+x6GE/oYM 6CCsq28ZCFhUMxUE858Wpj1xkdBUhRepPiXFqXA4d5WAXME6kK1eCrBYPXQGfIiI= X-Google-Smtp-Source: APXvYqyewEImIz5y7m23yNUjqFJ2BZCdOvkVTMkTraLqg4W7JaXxA2tx/+p5PC55KMTkxgyZdK7LrPOx6/pU X-Received: by 2002:a37:b441:: with SMTP id d62mr916095qkf.259.1557175710206; Mon, 06 May 2019 13:48:30 -0700 (PDT) Date: Mon, 6 May 2019 13:48:22 -0700 In-Reply-To: <87o94k7z6a.fsf@gmx.de> Message-Id: <20190506204821.161730-1-jktomer@google.com> Mime-Version: 1.0 References: <87o94k7z6a.fsf@gmx.de> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog Subject: [PATCH v6] Don't rewrite buffer contents after saving by rename From: Jonathan Tomer To: 35497@debbugs.gnu.org, eliz@gnu.org, michael.albinus@gmx.de Content-Type: text/plain; charset="UTF-8" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 35497 Cc: Jonathan Tomer X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) When `file-precious-flag' is non-nil, files are saved by renaming a temporary file to the new name; this is an atomic operation on POSIX so other programs will not see the file in an intermediate state. Unfortunately, due to a paren-matching error introduced in change 574c05e219476912db3105fa164accd9ba12b35f, we would then write the contents again in the usual way after this rename. In addition to being wasteful, this is a serious bug: the whole point of `file-precious-flag' is to prevent race conditions with other programs that might otherwise see an empty file, but with this bug the race is actually much *more* likely to be visible: the rename will alert any inotify watchers of a change, and then the subsequent write is very likely to truncate the file just as those programs start to read it! * lisp/files.el (basic-save-buffer-2): Don't rewrite file contents after saving-by-renaming. * test/lisp/files-tests.el (files-tests-dont-rewrite-precious-files): * test/lisp/net/tramp-tests.el (tramp-test10-write-region-file-precious-flag): Regression tests for this change. --- lisp/files.el | 4 ++-- test/lisp/files-tests.el | 15 +++++++++++++++ test/lisp/net/tramp-tests.el | 30 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index c05d70a00e..72518e8127 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5256,7 +5256,7 @@ basic-save-buffer-2 (set-file-extended-attributes buffer-file-name (nth 1 setmodes))) (set-file-modes buffer-file-name - (logior (car setmodes) 128)))))) + (logior (car setmodes) 128))))) (let (success) (unwind-protect (progn @@ -5272,7 +5272,7 @@ basic-save-buffer-2 (and setmodes (not success) (progn (rename-file (nth 2 setmodes) buffer-file-name t) - (setq buffer-backed-up nil)))))) + (setq buffer-backed-up nil))))))) setmodes)) (declare-function diff-no-select "diff" diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index ae8ea41a79..fe2e958f1c 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1244,5 +1244,20 @@ files-tests-file-attributes-equal (executable-find (file-name-nondirectory tmpfile)))))) (delete-file tmpfile)))) +(ert-deftest files-tests-dont-rewrite-precious-files () + "Test that `file-precious-flag' forces files to be saved by +renaming only, rather than modified in-place." + (let* ((temp-file-name (make-temp-file "files-tests")) + (advice (lambda (_start _end filename &rest _r) + (should-not (string= filename temp-file-name))))) + (unwind-protect + (with-current-buffer (find-file-noselect temp-file-name) + (advice-add #'write-region :before advice) + (setq-local file-precious-flag t) + (insert "foobar") + (should (null (save-buffer)))) + (ignore-errors (advice-remove #'write-region advice)) + (ignore-errors (delete-file temp-file-name))))) + (provide 'files-tests) ;;; files-tests.el ends here diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index cba697da18..2e25f23b23 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -41,6 +41,7 @@ ;;; Code: +(require 'cl-seq) (require 'dired) (require 'ert) (require 'ert-x) @@ -2270,6 +2271,35 @@ tramp--test-print-duration ;; Cleanup. (ignore-errors (delete-file tmp-name)))))) +(ert-deftest tramp-test10-write-region-file-precious-flag () + "Check that `file-precious-flag' is respected with Tramp in use." + :tags '(:unstable) + (skip-unless (tramp--test-enabled)) + (skip-unless (tramp--test-sh-p)) + + (let* ((tmp-name (tramp--test-make-temp-name)) + written-files + (advice (lambda (_start _end filename &rest _r) + (push filename written-files)))) + + (unwind-protect + (with-current-buffer (find-file-noselect tmp-name) + ;; Write initial contents. Adapt `visited-file-modtime' + ;; in order to suppress confirmation. + (insert "foo") + (write-region nil nil tmp-name) + (set-visited-file-modtime) + ;; Run the test. + (advice-add 'write-region :before advice) + (setq-local file-precious-flag t) + (insert "bar") + (should (null (save-buffer))) + (should-not (cl-member tmp-name written-files :test #'string=)) + + ;; Cleanup. + (ignore-errors (advice-remove 'write-region advice)) + (ignore-errors (delete-file tmp-name)))))) + (ert-deftest tramp-test11-copy-file () "Check `copy-file'." (skip-unless (tramp--test-enabled)) -- 2.21.0.1020.gf2820cf01a-goog From debbugs-submit-bounces@debbugs.gnu.org Tue May 07 10:03:41 2019 Received: (at 35497) by debbugs.gnu.org; 7 May 2019 14:03:41 +0000 Received: from localhost ([127.0.0.1]:59270 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO0h3-0000FC-0G for submit@debbugs.gnu.org; Tue, 07 May 2019 10:03:41 -0400 Received: from mout.gmx.net ([212.227.17.22]:58593) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO0gx-0000Et-MC for 35497@debbugs.gnu.org; Tue, 07 May 2019 10:03:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1557237805; bh=E/NwX5xflGrGyWmXoEc0HjzBjOvU4SoLoTuY8XyinCE=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=UnN0TUKuOsgNPF4uP6Vc+Qfu3RadAwXsJXCO7VXp7+1L0QvmnFE2VCgnqfpKlheLA 19Yh7X2/rpm4AUlUGnoPHjNLKTvj9X/mfInr/dl87+K0mHEq0gCa7zGpJ7scT0M7+r 58ibNFd6c420kOJ8Zor4187UcM5MezenXET+OHJk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from detlef.gmx.de ([213.220.159.171]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MqJmF-1gtN1y1NxL-00nU4Q; Tue, 07 May 2019 16:03:25 +0200 From: Michael Albinus To: Jonathan Tomer Subject: Re: [PATCH v6] Don't rewrite buffer contents after saving by rename References: <87o94k7z6a.fsf@gmx.de> <20190506204821.161730-1-jktomer@google.com> Date: Tue, 07 May 2019 16:03:24 +0200 In-Reply-To: <20190506204821.161730-1-jktomer@google.com> (Jonathan Tomer's message of "Mon, 6 May 2019 13:48:22 -0700") Message-ID: <871s1a2wgj.fsf@gmx.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:uyX3lkRPk21LruiYqL2HboF6MQHoXUbfzk/c2yZuMAwBQ9x5l7c foOjbPbM71Smx4teVDQXpoOd3oMLi4uDGOExVrED3qWuk2PQAv3vUmPbOYCiLmqllLUCbou kHfU2choEXubKhNy1rXwR8eoEZ8PSv50BMde2mQ5WRiop1Wd0BDmvzVwC+8um15NblssHeS e/kuxxHfrCwJx5eMhEzlA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:bWud2W/o/JY=:OMobAh+EFiQVZ0XfSnotnH FwPBmLaMFlBxSnntaFDzjMjZ29OeExxnfDzrUxCgFYGzNEdiSPtAd10mbO1f2Zq2itobD0RhY NIbHBDklln4pPSUDvpkOQml/XXJYO7d9G0XNdAlOk9f8HBP6zcNfJFn66FSQciugMJUac5Y9A 4ek4MY7ybtVuDkjkl79LIRxzvauweIWML7aJL+sue5J7Gb6xW3PddMudczjunPDxMNNG06J+E t4ht7IzyW+Hux/kBio5ZPUhwWOENzMC0AEcyfIHD1oAV0iCaDcMQqwjY2YR0P1RQ3NwZe0SKl LtD/+dzQWlqSuJ3rV2u3S7JWnLtbQa6ZT+fKy/fTVsEMw/PyEOL9NCsB1nX2pOkNI2YorhWpJ tAH/bsXJd1FM5t+/UgaI2jCh0uR/BvXDNP0HvDeRRNSd0hOgqKdXTg1cdJVtB7y5rQ9+2i4fS zh0TdBFS9GdmHo6e8zLC7RLxz8ysZUF0fqz/K4vPI4rUWhwbIOTyzUDa02viv+uvZobG0g73G tjqMr7voezBXkCgnoeCEGpbiWVxKdu7vQc7N1bNRga+dPPIqERfTckRsH2NuWyy31qVlf828b ahGiRW/TWFaGho6xlsaNPoQOQ7h37SfFbt4Zgc+n6IfKkS/OEVoDDpQ4Zj+LWDQDlWD4sYABH AbPkH1lHbkRlCA/M5QWgRZWYeDQQb9Fpu5EKG/Ev0hX9m3JmFQot2P1wSg9QW8PveKGaJne66 Zx4oNLL8IncLxRagtGS6D0MAWT4D49Qd8nNmnEv9/6BG1v3zttiVIqy4cQMcsUJzQfyxKgSNi 0t2TPqGokcwTs7Xxql2c6URUHrxxkwCB9Vj0MvetoCB3ZPPecBM9wkMEvAdGcY5pAepDrCeqo xpbWVLdb2Y+76rU3aht58FL/c3LyCui/I3jyLSaXIC8Wqe/DyhaxIhRZOt+b8CXSaK9Okor7u +1E7DslYWMg== X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 35497 Cc: eliz@gnu.org, 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Jonathan Tomer writes: > +(ert-deftest tramp-test10-write-region-file-precious-flag () > + "Check that `file-precious-flag' is respected with Tramp in use." > + :tags '(:unstable) > + (skip-unless (tramp--test-enabled)) > + (skip-unless (tramp--test-sh-p)) > + > + (let* ((tmp-name (tramp--test-make-temp-name)) > + written-files > + (advice (lambda (_start _end filename &rest _r) > + (push filename written-files)))) > + > + (unwind-protect > + (with-current-buffer (find-file-noselect tmp-name) > + ;; Write initial contents. Adapt `visited-file-modtime' > + ;; in order to suppress confirmation. > + (insert "foo") > + (write-region nil nil tmp-name) > + (set-visited-file-modtime) > + ;; Run the test. > + (advice-add 'write-region :before advice) > + (setq-local file-precious-flag t) > + (insert "bar") > + (should (null (save-buffer))) > + (should-not (cl-member tmp-name written-files :test #'string=)) I believe a closing parenthesis ")" is missing. > + ;; Cleanup. > + (ignore-errors (advice-remove 'write-region advice)) > + (ignore-errors (delete-file tmp-name)))))) Best regards, Michael. From debbugs-submit-bounces@debbugs.gnu.org Tue May 07 10:06:05 2019 Received: (at 35497) by debbugs.gnu.org; 7 May 2019 14:06:05 +0000 Received: from localhost ([127.0.0.1]:59278 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO0jI-0000Ij-Jx for submit@debbugs.gnu.org; Tue, 07 May 2019 10:06:05 -0400 Received: from mout.gmx.net ([212.227.15.19]:41631) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO0jC-0000IR-Rr for 35497@debbugs.gnu.org; Tue, 07 May 2019 10:05:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1557237946; bh=YotWflTILwyyzTgF1G0rZZNyExSfYpfZ7z6pwtkn56Q=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=WRY3TVvhlhbeUb89l6ZAGxd0/2tYFcm3ON80tQ+FC6eSzZVThO0Aw2Pj3m1mvyg1+ FAG768vRz4G6MXqVdYFfBm7SzyyhUhIl3QuznoDaA8OlmOzRYwxUgBWBCYsrDCcs0t OmphTR3tbYJ6bXeKZ8Helq0FJ9DNjvMR7fLXcDa4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from detlef.gmx.de ([213.220.159.171]) by mail.gmx.com (mrgmx002 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MEWPx-1hUMV92qQj-00Fnq7; Tue, 07 May 2019 16:05:46 +0200 From: Michael Albinus To: Jonathan Tomer Subject: Re: [PATCH v4] Don't rewrite buffer contents after saving by rename References: <87ftpx5b33.fsf@gmx.de> <20190502220649.129146-1-jktomer@google.com> <87o94k7z6a.fsf@gmx.de> Date: Tue, 07 May 2019 16:05:45 +0200 In-Reply-To: (Jonathan Tomer's message of "Mon, 6 May 2019 13:45:24 -0700") Message-ID: <87woj21hs6.fsf@gmx.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:1KlSYAcVLIRRp9HJ4nhvBlbJEvLupyNpXWVUEJQPc5i67dbdY0S tF6NqFyuVATEurGLiWGtODfN3WQ2O/AVcnf8LRDcfen6+j1iKv38iX7gr0sFRgKOuiPojVS yRCC8vs+vl/5V3+rUMxa0kJ9cuKwTd6iD175CBiHvopkBxnj7SdEOMjonSlBDJU7chWbs+0 ppG//Vtp/Xcjlm01WS5uw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:kPQ3uUkEA9w=:YWADVhL41QZrLtTeiQPA12 aNCyoiRbc54YRYzfKB6SGQaYtUS9IyyZLiMohxEHBvtbPG12T1kKan+Vwm+cp8r4XrmYGQjUI c/NSRgJD1QDvsLI54jKgCyT1tDJz1fTgkQud8Fu/UxyxaMWYzlIbIAIbR82AT8afGBsscnenw qibtv7UkD+vy0GZbzVHlI0nY+leLgNYqfd4f8y0aKmuN2AWCTdOoRGetctDynHnRjciK+VUuE hbQlM+zYkyARV1Oyc0frHyh2jcmKPFpBzeOKVSKOqh4dyvAxHf1NdNfIcNwtSY1IzihiFaIYn 4BWasAS3BtK6JhXX2LIRdSe8ZqUZcy27BpEk1FtMo6IqQFCZ3SQceMcUhUWXwVTVglWMQ8dgH NK50Wr+6DiPam+fV4p7qYiZhFEuIiUv8ZJiSqoxfN70JuHBOUvJyDvubdZ8Dsie3bkHnb/bvk i7d+RWr6NJnoasJhOCzJf1/DtR5YmngZGHlVhYr26U3tsrPqWhkGLlp6wVsDOA3row0Eri4qF SJQ1SFGvniLYm+Dm2BbTJ1Nf+LAOSziJHRzFMz6CoqHTdhas2J5fkk+KPbFPCOTO2joXp+DnM kd1F1M3I+/Ije+NsKF1cdYlHN1Uev6a2oZzV0WdZQk2tMISs6AUpPBply3dYM0IL3CrBNatrJ rsRlvD32NaS+BxvRbCc4ugjiFgkqHHl6qGqz0+zE5IDZx1Z12zNnin93NrRY99/N1PETLE1du 7pypHZZas1PhtPaBgmCOTY8iKAp6nTMSCyxqIcTffyJZmg6sIiosGexiRogA2mA4L25+6Rs/I inZgXpcnj7c7C4zYFgS6zZG+MxZsGlREXiJFdEJd+VeJgJowEtJ2T90LoxkupacSNhJsnUnpq L4mzS8kG7n4PcKnowx9ZuK4DZlmiqZp6DUH2MPpRmIJkTQci9ZYTIpWje8yI4aOmwfaQMqSbs XUGZS51uWWw== X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 35497 Cc: Eli Zaretskii , 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Jonathan Tomer writes: Hi Jonathan, > As eliz@ notes, I cannot sign the personal form of the copyright > assignment while I work for Google, since I have no copyright to > assign, but Google's assignment should suffice. I didn't know this special Google rule. OK. If the dust has settled, I could commit it then in your name. Best regards, Michael. From debbugs-submit-bounces@debbugs.gnu.org Tue May 07 10:11:09 2019 Received: (at 35497) by debbugs.gnu.org; 7 May 2019 14:11:09 +0000 Received: from localhost ([127.0.0.1]:59285 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO0oH-0000Qg-G1 for submit@debbugs.gnu.org; Tue, 07 May 2019 10:11:09 -0400 Received: from mout.gmx.net ([212.227.15.18]:51921) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO0oF-0000Q8-07 for 35497@debbugs.gnu.org; Tue, 07 May 2019 10:11:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1557238259; bh=ZqXADNoH6vv0EFLYnMDl8DHeTYCzU5bMWSF07e5N7TY=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=IJi509qfJ6kyz5+KGK7LKsXfYzPfdtMmtLekfpe4pnjrsdgKjBD6KSPA+HyuC40Ln XOV7Y2ZYjyZE9M5WABqZGta6df/Tj96gImzopw4cZS6ZS2K1RwZVonQshgjRsy51c3 XGuUnVMmSJGqDdztdMUqrNbNRd1LjBHvV4KIM8Vs= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from detlef.gmx.de ([213.220.159.171]) by mail.gmx.com (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N9dwd-1gcOHu0JqH-015dSE; Tue, 07 May 2019 16:10:59 +0200 From: Michael Albinus To: Jonathan Tomer Subject: Re: [PATCH v6] Don't rewrite buffer contents after saving by rename References: <87o94k7z6a.fsf@gmx.de> <20190506204821.161730-1-jktomer@google.com> <871s1a2wgj.fsf@gmx.de> Date: Tue, 07 May 2019 16:10:58 +0200 In-Reply-To: <871s1a2wgj.fsf@gmx.de> (Michael Albinus's message of "Tue, 07 May 2019 16:03:24 +0200") Message-ID: <87r29a1hjh.fsf@gmx.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:pSo1ItcIhM5hyzfqzp4Ud90E2Nx14+v2hAGoxCzPeiWlyBej8wj QZ3YhoQxL6c0ibcbTEvRZxpBGafELTaRC2qvQx2YenF4IoztVeC/YmGElfHEzqgxY7gwEWe x3OTwh/f+BWU+fsKcwPyGILxgrkk9I8VgWX5W/Cw4i1c+113oLevS8tOIZa+8msil8ou+V7 10O6D4ovmwAwJB/DSNrcQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:Cg+/LuWqgTE=:aOCADoR4oqTTZXpD8B8JHM /CaqMlI9U/orhAfCYr+orwlyZjblei/roucvNAdBQpMPuqMg1dAgqvEq76cTMDyiup+Fm+JnT XJghhNZWhLknJYeGy1tNAP31Bl9KMM5HsCURfV8T4+qZ6VpHLBX4yiD6k84pBOt+nge10U0Uj UDtrYT+rv/wo8rzVWSmk2E6KuyLhlxjlrDPmJHZf/1k3PLA6aLTMQFjmz7334Byb3eJ+n3I1/ onPSr0/oO+OYRMl4fZGGDGX+fK368O2xi9IY4lH+flzRr25htWxG6km+/ke4Ld4RHi/iNDU1B 0aNAYNhWlAJJkp8FMkm/gXrIJfErIAEtlEw5B4LFBiWnbzlpq9P5htD/cpK+mhmdtD/yeeFe3 Yb/wV70p2/itW4EdIj3mcgHHFyVogr9VDX6o2IrkQpzLVtyzjTc/h+pO9rCinHm4G6xnS/YFR d1z99xjfMAI9FI0Nv5Jj4sqAZhrn6CPROhwodhy1acKEtl/6ZoxKLG2TIt2QYFxUJcZEfmwg/ qHHhaN46SW8tpislaVuFSHr4hIZ2GnsTqaeUBI4299jZxNUmEi50GdUFRMJ6G37VMR1Dcu3ew +IacRcP4WFp0tF8LP6G+cL7Uyxb9wgc1OTqg5HPW7CA8AN5JL9dkweImcg1CAz4wK+jdTCQXA HzUma+WRKq4e4ljM2nfcMvTV8/5oPXm47bhHuA9FCb4EVS4zmm3bytbjdrSNAIGktOpT5T+Fj a85BmPsS5l9Ms+9ZHkgVbvVWnny/dCL2GChjilGmEL0fLCOqISIT6BnwzOKmX6rMF95yZ3sqs j1k0IO7sYKq7Kf3s80nGjRSkUJ9SkwwJu0iHctq4ztcCAmesL3HBB+dNHY5oC6sUiqKH8RyRB FF2GiHn5Pk3o2WedyZGRBML/Otw3KjePt0RcRwxSuenFYmv6tDZ6RFAL4/+YYbAyM4OlZSBh5 IlyjIHewO4w== X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 35497 Cc: eliz@gnu.org, 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Michael Albinus writes: > I believe a closing parenthesis ")" is missing. PS: When this is fixed, the test passes for me. Best regards, Michael. From debbugs-submit-bounces@debbugs.gnu.org Tue May 07 13:25:40 2019 Received: (at 35497) by debbugs.gnu.org; 7 May 2019 17:25:40 +0000 Received: from localhost ([127.0.0.1]:59485 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO3qW-0003DJ-Ee for submit@debbugs.gnu.org; Tue, 07 May 2019 13:25:40 -0400 Received: from mail-ua1-f68.google.com ([209.85.222.68]:42949) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO3qU-0003D6-HA for 35497@debbugs.gnu.org; Tue, 07 May 2019 13:25:38 -0400 Received: by mail-ua1-f68.google.com with SMTP id h4so6319491uaj.9 for <35497@debbugs.gnu.org>; Tue, 07 May 2019 10:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BNx2we0vpn/WBfHJlUVlMz310pMMRPCCsNbFHDUtpKc=; b=AW5gyw43D8oEHuTEsLnXOI5XZ//WgqXlcYAkSF2oM7jX2xS0NUUXZRj1dBiPm7/gOx xs6WpIITuEihWEQ/S7CXuG8oUHR6yBmDXj8Xdnc+y4NEN9xRl2l1LfGfErbtGZkN1s9E IQxe3pjMtLunZ6JbSezF6K40pJMZe1aBWz91a9lT3Ltwb1v7GyPe9qh+QxNSit790T2z W70t1kLCRLPYhICbTpJ9vbinPN3DDHKza5UGM1cCjOYl3TrhrE7R3fdt8aAVCrsKU+VS VioMGdZl+y98SW8HlkomGF37GUfmkWheMc2DYBb1UYFaeEfZqneW3l5/snY9jigT3vMe HjcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BNx2we0vpn/WBfHJlUVlMz310pMMRPCCsNbFHDUtpKc=; b=rWG31tGQ2cqquJ4ZiB4OaDWv3pcyIb0H5+BynG6CjlJENf/wdx+srFBI63NfO5tlHs C7u6sIA987BD9ztfb/U+YzgJMKpkQMoucNCcir7vRGINxvhQwwVZmUD1WNPBjwfJv2fv wZrBbHpsoGhoUL6eFuhUnjVJWiBlg7KWw5fznWEJ/RtGNbQevVnLDTOAd1XBWnqB3vCU fd57SYlE0/xQJlh8ll214Mtdu03GiQ84n/Z24VqNuMfWsshdQi129Qu5iphp5vttQ9uw bzavA4ZhXGsMzCpnkW+xasxAjENc9fugVQynMcOBuubLNdH6NIQjzxzOIfkr93kl6F+F cW1A== X-Gm-Message-State: APjAAAUxlOnXaqONt8hOijniMs9qNQ75nNUULBouGOT2i+5WCuaGAv6Z mgvxhwuXb/GVqDulPtioyAyLZ4IRLGwwFV/M8Lbopw== X-Google-Smtp-Source: APXvYqz717h/b9n6EbqdT+zJQnkswOAzDguYIvW6dh9Wyl+iFNKWvwA1ycM6ShXmSg+wfgpL3cAmqRHEmIQDBXx4n00= X-Received: by 2002:ab0:6595:: with SMTP id v21mr3887702uam.113.1557249932521; Tue, 07 May 2019 10:25:32 -0700 (PDT) MIME-Version: 1.0 References: <87o94k7z6a.fsf@gmx.de> <20190506204821.161730-1-jktomer@google.com> <871s1a2wgj.fsf@gmx.de> <87r29a1hjh.fsf@gmx.de> In-Reply-To: <87r29a1hjh.fsf@gmx.de> From: Jonathan Tomer Date: Tue, 7 May 2019 10:25:21 -0700 Message-ID: Subject: Re: [PATCH v6] Don't rewrite buffer contents after saving by rename To: Michael Albinus Content-Type: multipart/alternative; boundary="0000000000000e6a8b05884f817d" X-Spam-Score: -8.0 (--------) X-Debbugs-Envelope-To: 35497 Cc: Eli Zaretskii , 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -9.0 (---------) --0000000000000e6a8b05884f817d Content-Type: text/plain; charset="UTF-8" On Tue, May 7, 2019 at 7:11 AM Michael Albinus wrote: > Michael Albinus writes: > > > I believe a closing parenthesis ")" is missing. > > PS: When this is fixed, the test passes for me. > Whoops. Sending fix now, and removing unstable tag. > > Best regards, Michael. > --0000000000000e6a8b05884f817d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, May 7, 2019 at 7:11 AM Michael Al= binus <michael.albinus@gmx.de<= /a>> wrote:
Michael Albinus <michael.albinus@gmx.de&= gt; writes:

> I believe a closing parenthesis ")" is missing.

PS: When this is fixed, the test passes for me.

Whoops. Sending fix now, and removing unstable tag.
=C2= =A0

Best regards, Michael.
--0000000000000e6a8b05884f817d-- From debbugs-submit-bounces@debbugs.gnu.org Tue May 07 13:36:20 2019 Received: (at 35497) by debbugs.gnu.org; 7 May 2019 17:36:20 +0000 Received: from localhost ([127.0.0.1]:59514 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO40q-0003W1-5p for submit@debbugs.gnu.org; Tue, 07 May 2019 13:36:20 -0400 Received: from mail-qt1-f201.google.com ([209.85.160.201]:33539) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <3CsLRXAcKBcEqr0vtlynvvnsl.jvtACBGEklii1nz.nu1.vyn@flex--jktomer.bounces.google.com>) id 1hO40m-0003Vh-3k for 35497@debbugs.gnu.org; Tue, 07 May 2019 13:36:18 -0400 Received: by mail-qt1-f201.google.com with SMTP id n39so20105824qtn.0 for <35497@debbugs.gnu.org>; Tue, 07 May 2019 10:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=sOHF+Cg8spTTqQQDmoYVtmAyRqaLdh9GswGuyDjXY6o=; b=GrExdCzsf2kn0p/MoN3co32AQAbQiO1Wd1YRugbemaKrXBzf/5uvJqRbPggddShuXl fTqSfwFuHTUBd73X9H8h6SsA4HRT1KaROryAh68ZiUp/hb8tU+og7DjcKWFsC8leKVVh HutNmRPYSFS1xHCLaOyeaN7AXGN/rSXfa1t6/XwL+PDOBbKBVMBWBWJnh6ghtomYsfEw xFP8tYZEH2D3BxSioQx/BA3PUZDtzGrJA4A+5UVWnBXaqgua+lHjTWtH+V87AWmSRG0C MxmpuvUxG2ejAv3w3cpJF/3/ZoaXrNAmnSvgpIHSn0Q1Y4L9mPG4OMpnZRrfijUeEbEH 46bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=sOHF+Cg8spTTqQQDmoYVtmAyRqaLdh9GswGuyDjXY6o=; b=KvCjy2k6WlfQHKWPi8kEpwGQgEgy8a+gh2yzOBOty54j7zb4J1T2aZNu9e4A/S96K8 FI1J/VAuV6SR9X3UKCB9iM2qpJQ/ztDntKt+ocoCcEN5fKczC9IF+2Fum+utN4C9ASRR sQcOvcAEg2V07Yca9fKvtCgOZFoF3XL0zS7iF9E2PlPdQr0p2N5XxLHytjhY9OFop9/Q FAmXwoee+/W/td4W0m6BY5CWY/FERETPL26ORU5uRaMJBuQc2YsH6/OTzrJN0P66TTc1 qTZUTQXeH4SvKiwhy0wGkUExglZ6EsBcnl7VJ8U8dcFFqPjNG5U2KJqaBZC0yVqJILEh L3VA== X-Gm-Message-State: APjAAAV/z9AqYP+qHiCkjMb1YskwrxP84t8I/RnORi6Wj+GzRRn4322u LoSRvFp26oh3SqEolTPlrOS4jyXwU7B9OTwEJzRw0O0UQbCW4R33DEsR11U8chfjw8UG031ZGwC OcdFqd/v5gkrBcLBgi63wwI6vXZX/jWAYYKb9c7ggSgWNgkZ1LI6vkG4jHYnrUNg= X-Google-Smtp-Source: APXvYqxQJixvbeSBOrLet8MjS3mMH7uWdOqVtscFOf9YYcbKloxdIsZ1+WxFm0fl0JqN/vOeU+OIPqP0mtWC X-Received: by 2002:ac8:3701:: with SMTP id o1mr23112909qtb.98.1557250570386; Tue, 07 May 2019 10:36:10 -0700 (PDT) Date: Tue, 7 May 2019 10:33:28 -0700 In-Reply-To: <87r29a1hjh.fsf@gmx.de> Message-Id: <20190507173328.140935-1-jktomer@google.com> Mime-Version: 1.0 References: <87r29a1hjh.fsf@gmx.de> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog Subject: [PATCH v7] Don't rewrite buffer contents after saving by rename From: Jonathan Tomer To: 35497@debbugs.gnu.org, eliz@gnu.org, michael.albinus@gmx.de Content-Type: text/plain; charset="UTF-8" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 35497 Cc: Jonathan Tomer X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) When `file-precious-flag' is non-nil, files are saved by renaming a temporary file to the new name; this is an atomic operation on POSIX so other programs will not see the file in an intermediate state. Unfortunately, due to a paren-matching error introduced in change 574c05e219476912db3105fa164accd9ba12b35f, we would then write the contents again in the usual way after this rename. In addition to being wasteful, this is a serious bug: the whole point of `file-precious-flag' is to prevent race conditions with other programs that might otherwise see an empty file, but with this bug the race is actually much *more* likely to be visible: the rename will alert any inotify watchers of a change, and then the subsequent write is very likely to truncate the file just as those programs start to read it! * lisp/files.el (basic-save-buffer-2): Don't rewrite file contents after saving-by-renaming. * test/lisp/files-tests.el (files-tests-dont-rewrite-precious-files): * test/lisp/net/tramp-tests.el (tramp-test10-write-region-file-precious-flag): Regression tests for this change. --- lisp/files.el | 4 ++-- test/lisp/files-tests.el | 15 +++++++++++++++ test/lisp/net/tramp-tests.el | 29 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index c05d70a00e..72518e8127 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5256,7 +5256,7 @@ basic-save-buffer-2 (set-file-extended-attributes buffer-file-name (nth 1 setmodes))) (set-file-modes buffer-file-name - (logior (car setmodes) 128)))))) + (logior (car setmodes) 128))))) (let (success) (unwind-protect (progn @@ -5272,7 +5272,7 @@ basic-save-buffer-2 (and setmodes (not success) (progn (rename-file (nth 2 setmodes) buffer-file-name t) - (setq buffer-backed-up nil)))))) + (setq buffer-backed-up nil))))))) setmodes)) (declare-function diff-no-select "diff" diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index ae8ea41a79..fe2e958f1c 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1244,5 +1244,20 @@ files-tests-file-attributes-equal (executable-find (file-name-nondirectory tmpfile)))))) (delete-file tmpfile)))) +(ert-deftest files-tests-dont-rewrite-precious-files () + "Test that `file-precious-flag' forces files to be saved by +renaming only, rather than modified in-place." + (let* ((temp-file-name (make-temp-file "files-tests")) + (advice (lambda (_start _end filename &rest _r) + (should-not (string= filename temp-file-name))))) + (unwind-protect + (with-current-buffer (find-file-noselect temp-file-name) + (advice-add #'write-region :before advice) + (setq-local file-precious-flag t) + (insert "foobar") + (should (null (save-buffer)))) + (ignore-errors (advice-remove #'write-region advice)) + (ignore-errors (delete-file temp-file-name))))) + (provide 'files-tests) ;;; files-tests.el ends here diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index cba697da18..0c5ea03741 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -41,6 +41,7 @@ ;;; Code: +(require 'cl-seq) (require 'dired) (require 'ert) (require 'ert-x) @@ -2270,6 +2271,34 @@ tramp--test-print-duration ;; Cleanup. (ignore-errors (delete-file tmp-name)))))) +(ert-deftest tramp-test10-write-region-file-precious-flag () + "Check that `file-precious-flag' is respected with Tramp in use." + (skip-unless (tramp--test-enabled)) + (skip-unless (tramp--test-sh-p)) + + (let* ((tmp-name (tramp--test-make-temp-name)) + written-files + (advice (lambda (_start _end filename &rest _r) + (push filename written-files)))) + + (unwind-protect + (with-current-buffer (find-file-noselect tmp-name) + ;; Write initial contents. Adapt `visited-file-modtime' + ;; in order to suppress confirmation. + (insert "foo") + (write-region nil nil tmp-name) + (set-visited-file-modtime) + ;; Run the test. + (advice-add 'write-region :before advice) + (setq-local file-precious-flag t) + (insert "bar") + (should (null (save-buffer))) + (should-not (cl-member tmp-name written-files :test #'string=))) + + ;; Cleanup. + (ignore-errors (advice-remove 'write-region advice)) + (ignore-errors (delete-file tmp-name))))) + (ert-deftest tramp-test11-copy-file () "Check `copy-file'." (skip-unless (tramp--test-enabled)) -- 2.21.0.1020.gf2820cf01a-goog From debbugs-submit-bounces@debbugs.gnu.org Tue May 07 19:46:43 2019 Received: (at 35497) by debbugs.gnu.org; 7 May 2019 23:46:43 +0000 Received: from localhost ([127.0.0.1]:59948 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO9nG-0008Po-Dz for submit@debbugs.gnu.org; Tue, 07 May 2019 19:46:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50284) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO9nD-0008Pa-SO for 35497@debbugs.gnu.org; Tue, 07 May 2019 19:46:40 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:41653) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hO9n7-0001gr-Kf; Tue, 07 May 2019 19:46:33 -0400 Received: from rms by fencepost.gnu.org with local (Exim 4.82) (envelope-from ) id 1hO9n4-00013s-Kv; Tue, 07 May 2019 19:46:30 -0400 Content-Type: text/plain; charset=Utf-8 From: Richard Stallman To: Michael Albinus In-Reply-To: <87woj21hs6.fsf@gmx.de> (message from Michael Albinus on Tue, 07 May 2019 16:05:45 +0200) Subject: Re: bug#35497: [PATCH v4] Don't rewrite buffer contents after saving by rename References: <87ftpx5b33.fsf@gmx.de> <20190502220649.129146-1-jktomer@google.com> <87o94k7z6a.fsf@gmx.de> <87woj21hs6.fsf@gmx.de> Message-Id: Date: Tue, 07 May 2019 19:46:30 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 35497 Cc: jktomer@google.com, 35497@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: rms@gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > > As eliz@ notes, I cannot sign the personal form of the copyright > > assignment while I work for Google, since I have no copyright to > > assign, but Google's assignment should suffice. > I didn't know this special Google rule. OK. Actually it applies to most employees who are programmers. Usually we get the company to disclaim copyright so that the human author can assign copyright, but sometimes the company assigns the copyright itself. Either way is ok. -- Dr Richard Stallman President, Free Software Foundation (https://gnu.org, https://fsf.org) Internet Hall-of-Famer (https://internethalloffame.org) From debbugs-submit-bounces@debbugs.gnu.org Wed May 08 03:48:22 2019 Received: (at 35497-done) by debbugs.gnu.org; 8 May 2019 07:48:22 +0000 Received: from localhost ([127.0.0.1]:60258 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hOHJN-0006Ec-T8 for submit@debbugs.gnu.org; Wed, 08 May 2019 03:48:22 -0400 Received: from mout.gmx.net ([212.227.15.18]:33477) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hOHJL-0006EO-Si for 35497-done@debbugs.gnu.org; Wed, 08 May 2019 03:48:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1557301689; bh=g3FRBFJQA4hnJiuYBtb+tAzQ9cvt+PIAqgq9A5Inx6s=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=DySrhY9ipFmJKbd35Z66AHoTtXuEu2XPHhmmCMarshd5H444PVS6m+cpFopa27Lno hgj5+ose8GkVdHoF0ha+sJpBMXXfUPErrwz8I1EoqDy1nqr/rEC6IrtFo4Ii2XtRI7 E0SSmmIXisxjMwAjdCZfq+0QJOaMPon4yNfzLQqI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from detlef.gmx.de ([178.20.95.22]) by mail.gmx.com (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N5mKP-1gdmTq21CV-017A6u; Wed, 08 May 2019 09:48:09 +0200 From: Michael Albinus To: Jonathan Tomer Subject: Re: [PATCH v7] Don't rewrite buffer contents after saving by rename References: <87r29a1hjh.fsf@gmx.de> <20190507173328.140935-1-jktomer@google.com> Date: Wed, 08 May 2019 09:48:07 +0200 In-Reply-To: <20190507173328.140935-1-jktomer@google.com> (Jonathan Tomer's message of "Tue, 7 May 2019 10:33:28 -0700") Message-ID: <87h8a5idzc.fsf@gmx.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:dUbz2HrAQxxEjyoPodsAxdTNnZZVdj83b2axFiJR3tlbAdWYgYc 8c8sefKBMp2pdz1YC7F8qd2G+m9BmdPIKO9d0jMLYPiIj1ytNwIayEI+tEoMwmwO3dxVIeZ Kq/gRVBP83tE2rnHfj0Iv7LkPg7+/fO3kqz8fnrs+oR+tr1pFtvJKATk3md5UlWtit4rAB7 37KuCCpVufm/V7zEusv6g== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:fmes33XcCgY=:s8kTXQ8Z+kzMLhP2ojhJ8u UzY5JubPmsW+P3OnoBhhRhC9IbJc0JPIXsNSIqmwNfNmqXdWnvZCamJOGNLeyMzmN/i4w0xk7 0sQdBJIy/xtJHBrCA4YTmIf+GGhhCCrfAWkjh8hEyiBbuQb+wcb3ffGyh6JyzokVkaOKd2fgs h4NRhLGNoszNzmCvBmFrMnbWcSTo2XOLATA/J2NhyURMramgtOKy+0U2v5+iOj9IE0TmxFvc7 fpyFDPoHG3wMYeKBCZvB2frOhFVNWyor2rlWHPBeGIfsnI9QKrYr549smLZ5qx/uwoK/T93nm i2NObNSFyTUvewTn3eGYCv5J+NTV6smmysHmno8Icfcly5pj5EAWIc2tLpw7ZTEwPZG+zM5pF VaINqkexRNM0dP8Phv6cmadKFtqMfhxZ9h1eo16euy0HvHndnvdSEGktTBEIhqU3hM3u6Mrhh oXIATtjMdfHyzvSuozDwwTAf61Sk5qp6jwJF4oWLcNs/Y9RTZAaJfb5T9nN+LUCJbp2e4w/ir 2RABKYXV8E5Rczf+/ALAz61q2ZD/88zJiWV/1CO9UZ5GOrZtuUwybBZpZoL1K/r0znoOPo5gp GXnEkmiKIUMmr9U4qTYbkZtjwFxEknxwE0i2wRomVxnNKB4D0Lvde5CriRZHPIRr9OwFOmovE AW7AIOID6coC543n4V2gWob8uamLSbPt3iYWEP2lUvkQ70zG0lTaZX2rjr9dv7hpycu5kUqx9 ZFbAcgLUk22lKrhf//ZHzWjbXH6l9L0CHi0W3QbK+HVYyZJKKnlCjUroXt/hEMqkjv1Jth2Fs G87uZ5UpI5wGA0xBXsw+Y0rqQMoG15+bVATly4d3QjD1Q3c3OqLFitefoucYq+m/sn2T4qeL+ se1aMwtAFxgl1tJ4cY0PsUOsVq0LHvm+hO0Ngfr94vvESw8pbw/ljgohqjaUhl+LXaeeDe1k/ 3GlHx3ur9Yw== X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 35497-done Cc: eliz@gnu.org, 35497-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi Jonathan, thanks for this final version, I've pushed it to master. I've added a skip for Emacs < 27, since it fails there. Obviously. Marking the bug as closed. Best regards, Michael. From debbugs-submit-bounces@debbugs.gnu.org Wed May 08 13:03:48 2019 Received: (at 35497-done) by debbugs.gnu.org; 8 May 2019 17:03:48 +0000 Received: from localhost ([127.0.0.1]:33918 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hOPyt-0006ad-P6 for submit@debbugs.gnu.org; Wed, 08 May 2019 13:03:48 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:34325) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hOPyr-0006aO-UI for 35497-done@debbugs.gnu.org; Wed, 08 May 2019 13:03:46 -0400 Received: by mail-vs1-f66.google.com with SMTP id q64so2359958vsd.1 for <35497-done@debbugs.gnu.org>; Wed, 08 May 2019 10:03:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Sw6/RqgDgEPZKzfcpLJN+aqhp9k+aSIesDKH1GREE4g=; b=J7zlTm/BfiesM8Q8fgv9ofYulnDyrgp14plsVBIbmPe+zjqUwtvI2ITlR5+TcuCCvw pBJ+kQEoUgUMD32hqXgwJT24jZbx5EImqKQ8qlKAxhpxoYqn+VU+ppi5AycW7fHKbgru n+et+I4nnL2BaVvISInfTyuP3Ynf9bUBnT8fUdPYdAtFESfJq4jqGX1ePD8yWgDwcoc1 BwuYbUbp/1U2OcbksbyIiQZDhuaZuuM1NJHNVVj6KVUxy+8/qi9UBlNHsY39VMTQkJQ0 rfH+vqlS26jc9A8zdRsJLUVuoqEFWWmpsbU8UNgGVbLEIa7tgrLhMxigTEHfalTna1jj +pgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Sw6/RqgDgEPZKzfcpLJN+aqhp9k+aSIesDKH1GREE4g=; b=HAOBCrV/BMMjlTwNcTlMreFGExbXB9S7bfzYzWI03UdK+9v4N3ZsLcoKzapDaUezNK 9WyaGZOTtSQ68poxjS9a1J5TTIDYTvy5r0VjWuTXIlZ2hsrzwrjOQsYcLXJF8PERy/bD VnAVm9M7FjpTK+1bbHrwdU1KvmkatrkUmPfgyq+ylY5IWdW179JPhLPsGt2I/EyeJS+d gYm/3wGQcAOTL5u7lhyKSmyhvaiiSkguXUW8wrW5ArkzzClY3NUqK2qLuc92i/2xljBf h6tsUxEnC8HBq0b2UR1Fh0Gon890mc1ejqGEueBk5/O1rTCzy4HQpxRxMosWdT+jIAkS 8qpg== X-Gm-Message-State: APjAAAWi4xDasaLsut45BzDiwbSUK5EGk1+h76GqayisXmysIVEMlc2C AzmBlQsPni5V3LG3etaQB/+J0w3699lLzrefTVUrvQ== X-Google-Smtp-Source: APXvYqxSvHjhVl9grAMp7Abj7kZ2sHmoR1xeBiDVmp1rdb6bahK3M2B6iDh/NuRmsyCU0vSSuYOjcntNqzUOjhBhVoc= X-Received: by 2002:a67:e44f:: with SMTP id n15mr5039389vsm.218.1557335019062; Wed, 08 May 2019 10:03:39 -0700 (PDT) MIME-Version: 1.0 References: <87r29a1hjh.fsf@gmx.de> <20190507173328.140935-1-jktomer@google.com> <87h8a5idzc.fsf@gmx.de> In-Reply-To: <87h8a5idzc.fsf@gmx.de> From: Jonathan Tomer Date: Wed, 8 May 2019 10:03:27 -0700 Message-ID: Subject: Re: [PATCH v7] Don't rewrite buffer contents after saving by rename To: Michael Albinus Content-Type: multipart/alternative; boundary="0000000000009bfa93058863504c" X-Spam-Score: -8.0 (--------) X-Debbugs-Envelope-To: 35497-done Cc: Eli Zaretskii , 35497-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -9.0 (---------) --0000000000009bfa93058863504c Content-Type: text/plain; charset="UTF-8" Thanks! On Wed, May 8, 2019 at 12:48 AM Michael Albinus wrote: > Hi Jonathan, > > thanks for this final version, I've pushed it to master. I've added a > skip for Emacs < 27, since it fails there. Obviously. > > Marking the bug as closed. > > Best regards, Michael. > --0000000000009bfa93058863504c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks!

On Wed, May 8, 2019 at 12:48 AM Michael Albinus <= ;michael.albinus@gmx.de> w= rote:
Hi Jonatha= n,

thanks for this final version, I've pushed it to master. I've added= a
skip for Emacs < 27, since it fails there. Obviously.

Marking the bug as closed.

Best regards, Michael.
--0000000000009bfa93058863504c-- From unknown Fri Aug 15 12:50:54 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 06 Jun 2019 11:24:08 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator