From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#66546: 30.0.50; save-buffer to write-protected file without backup fails Date: Sat, 04 Nov 2023 10:58:18 +0200 Message-ID: <8334xl6gk5.fsf@gnu.org> References: <87edhvd84h.fsf@sappc2.fritz.box> <838r82q0gi.fsf@gnu.org> <87wmvmfi68.fsf@sappc2.fritz.box> <83o7gxo771.fsf@gnu.org> <87ttqpgg8l.fsf@sappc2.fritz.box> <83cyxcnp2f.fsf@gnu.org> <87sf671xe3.fsf@sappc2.fritz.box> <83y1fzmdhm.fsf@gnu.org> <87zg0ez57o.fsf@sappc2.fritz.box> <835y31u8t0.fsf@gnu.org> <87edhnamg3.fsf@sappc2.fritz.box> <83a5sbre7x.fsf@gnu.org> <87bkcrafxt.fsf@sappc2.fritz.box> <834jijqmnd.fsf@gnu.org> <878r7v9ei7.fsf@sappc2.fritz.box> <838r7qkgdp.fsf@gnu.org> <5097ddb3-c8a9-47ce-a6da-4ab73ca31172@vodafonemail.de> <838r7lbih3.fsf@gnu.org> <87wmv1wawz.fsf@sappc2.fritz.box> <83bkcc8xe5.fsf@gnu.org> <87fs1mh7p0.fsf@sappc2.fritz.box> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6575"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 66546@debbugs.gnu.org To: Jens Schmidt Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 04 09:59:45 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qzCVM-0001Um-1X for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 04 Nov 2023 09:59:44 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qzCV7-0002oT-Pp; Sat, 04 Nov 2023 04:59:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qzCV6-0002oI-DE for bug-gnu-emacs@gnu.org; Sat, 04 Nov 2023 04:59:28 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qzCV6-0003M2-4x for bug-gnu-emacs@gnu.org; Sat, 04 Nov 2023 04:59:28 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qzCVe-000091-OG for bug-gnu-emacs@gnu.org; Sat, 04 Nov 2023 05:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 04 Nov 2023 09:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66546 X-GNU-PR-Package: emacs Original-Received: via spool by 66546-submit@debbugs.gnu.org id=B66546.1699088344428 (code B ref 66546); Sat, 04 Nov 2023 09:00:02 +0000 Original-Received: (at 66546) by debbugs.gnu.org; 4 Nov 2023 08:59:04 +0000 Original-Received: from localhost ([127.0.0.1]:60745 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qzCUh-00006n-Kt for submit@debbugs.gnu.org; Sat, 04 Nov 2023 04:59:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55348) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qzCUf-000069-Pp for 66546@debbugs.gnu.org; Sat, 04 Nov 2023 04:59:02 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qzCTz-0003BG-Pr; Sat, 04 Nov 2023 04:58:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=qXqtwFfblY7lbskoBIVWzkXIYdDhKRWnwafmFb+Frt8=; b=IEz7/m2dGmou eBuPNYzSgOe8VnZgg/QsIlutgECKJV7clzgTpA2PVjfJKwZdd3RqHw9f4LKy0ShBxxM6wzVWmEl8G R7aSH1+AzNc1yvnF5Y5oRjQ3x1ZeHvJ20v+S5iWuWLdOqXXy8ES0gSBC96q7RqfA7kO6zbD72g3fA nHLg2ztMBODKt/SA1NnjpodNFS5SY2hATYHmh247di4wreOxyJbs6FWX0wEWesrj8aR8WEc1sKFjO J4LuPp2q8kJnxuei15mJkxtSx4KhjfKS2r0it1nIQtgxhSBrnGAB3c3bIWqQn4sqt4972Fn0zMCYJ 7kHx205OLfhrOkw1z9TJbA==; In-Reply-To: <87fs1mh7p0.fsf@sappc2.fritz.box> (message from Jens Schmidt on Fri, 03 Nov 2023 22:02:03 +0100) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:273759 Archived-At: > From: Jens Schmidt > Cc: 66546@debbugs.gnu.org > Date: Fri, 03 Nov 2023 22:02:03 +0100 > > > If you want to make sure the file's contents is _exactly_ some text, > > you need to write the buffer text to the file with no encoding > > conversions, and you need then to visit the file with > > insert-file-contents-literally, to avoid decoding conversions. > > Otherwise you might get false positives and false negatives due to > > encoding/decoding of text and of EOLs. > > Done: insert-file-contents-literally for reading, binding > > (coding-system-for-write 'no-conversion) > > for writing. I think one nit is still missing: > + (let* (;; Sanitize environment. > + (coding-system-for-write 'no-conversion) I think you also need to bind coding-system-for-read to no-conversion, since you later do this: > + (with-current-buffer (find-file-noselect file) ^^^^^^^^^^^^^^^^^^^^^^^ Otherwise, find-file-noselect will use insert-file-contents, which will attempt to decode the text. Thanks.