From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jens Schmidt via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#66546: 30.0.50; save-buffer to write-protected file without backup fails Date: Tue, 17 Oct 2023 22:12:58 +0200 Message-ID: <87ttqpgg8l.fsf@sappc2.fritz.box> References: <83h6mtq9t7.fsf@gnu.org> <8734ydx7x3.fsf@sappc2.fritz.box> <83cyxgqwjm.fsf@gnu.org> <87lec4cjqe.fsf@sappc2.fritz.box> <83ttqsp5x1.fsf@gnu.org> <87il78cdyf.fsf@sappc2.fritz.box> <83pm1gozi6.fsf@gnu.org> <87edhvd84h.fsf@sappc2.fritz.box> <838r82q0gi.fsf@gnu.org> <87wmvmfi68.fsf@sappc2.fritz.box> <83o7gxo771.fsf@gnu.org> Reply-To: Jens Schmidt Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40366"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cc: 66546@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 17 22:14:00 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 1qsqS0-000AF7-Li for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 17 Oct 2023 22:14:00 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsqRg-0005zo-EY; Tue, 17 Oct 2023 16:13:40 -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 1qsqRd-0005xr-2d for bug-gnu-emacs@gnu.org; Tue, 17 Oct 2023 16:13:37 -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 1qsqRc-0006hX-Qj for bug-gnu-emacs@gnu.org; Tue, 17 Oct 2023 16:13:36 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qsqS2-0002QP-BK for bug-gnu-emacs@gnu.org; Tue, 17 Oct 2023 16:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jens Schmidt Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 17 Oct 2023 20:14: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.16975736249288 (code B ref 66546); Tue, 17 Oct 2023 20:14:02 +0000 Original-Received: (at 66546) by debbugs.gnu.org; 17 Oct 2023 20:13:44 +0000 Original-Received: from localhost ([127.0.0.1]:32854 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qsqRk-0002Pk-Aq for submit@debbugs.gnu.org; Tue, 17 Oct 2023 16:13:44 -0400 Original-Received: from mr5.vodafonemail.de ([145.253.228.165]:57920) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qsqRg-0002PV-SP for 66546@debbugs.gnu.org; Tue, 17 Oct 2023 16:13:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vodafonemail.de; s=vfde-mb-mr2-23sep; t=1697573589; bh=rWfIcBS7VOxyJOLioRFAk6lCmmZhRjF7nEwkWhgQZ3g=; h=From:To:Subject:References:Date:In-Reply-To:Message-ID:User-Agent: Content-Type:From; b=pORXA1hw3zUbWXpQqJ7QO0CopnEvbXXLOSBtQCDR8z0VCOrza8HeICMfYOKhVZHGL 5pty9nipn/0xvoVluaKGJlL7CqYzlCxPClzK9oPL0X1OHCrx6gFSZOpFpEQ/fNfDhD H4NCJmVZQ3cEktwlZHfaaaU5cQJQ2iYQwkMkej9o= Original-Received: from smtp.vodafone.de (unknown [10.0.0.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mr5.vodafonemail.de (Postfix) with ESMTPS id 4S94sx5m1Kz1y8s; Tue, 17 Oct 2023 20:13:09 +0000 (UTC) Original-Received: from sappc2 (port-92-194-134-94.dynamic.as20676.net [92.194.134.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp.vodafone.de (Postfix) with ESMTPSA id 4S94sp27hjzMm7L; Tue, 17 Oct 2023 20:12:59 +0000 (UTC) In-Reply-To: <83o7gxo771.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 17 Oct 2023 13:48:50 +0300") X-purgate-type: clean X-purgate: clean X-purgate-size: 3491 X-purgate-ID: 155817::1697573585-B2FF9228-A7AD39EF/0/0 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:272635 Archived-At: Eli Zaretskii writes: >> From: Jens Schmidt >> Cc: 66546@debbugs.gnu.org >> Date: Mon, 16 Oct 2023 22:04:15 +0200 >> >> Eli Zaretskii writes: >> >> > I've now installed that on the master branch. >> >> Thanks. Now that's out of the way, should I then work on what I have >> called issue B in the initial message and on ERT tests for both issues? >> Or do you still think there is more discussion required on these >> beforehand? > > I'd like to ask you to show the relevant code again and explain why it > doesn't do the job in that case. Let's postpone that for the time being. I feel that there is still a basic misunderstanding here. Do we agree that this bug is all about the "no-backup" case (*C-0* C-x C-s)? For me that means: I want to save to file "foo", and I explicitly do not want Emacs to create or touch a backup file "foo~" for that. As a consequence, during the whole operation, there is only _one_ file being involved, and not some second one, both as far as Emacs and the operating system are concerned. If I were to write a function replacing `basic-save-buffer-2' just for that special "no-backup" case, then this way: (defun basic-save-buffer-2-no-backup () (interactive) ;; ... user confirmation elided here ... (setq setmodes (list (file-modes buffer-file-name) (file-extended-attributes buffer-file-name) buffer-file-name)) ;; No need to call `set-file-extended-attributes' here, since ;; we only have one file, and we just got the extended ;; attributes from that file. (set-file-modes buffer-file-name (logior (car setmodes) 128)) (let (success) (unwind-protect (progn (write-region nil nil buffer-file-name nil t buffer-file-truename) (setq success t)) (and setmodes (not success) (progn ;; No sense in calling `rename-file' here as done ;; in `basic-save-buffer-2', since we only have ;; one file. (set-file-extended-attributes buffer-file-name (nth 1 setmodes)) (setq buffer-backed-up nil))))) setmodes) >> And wouldn't that be, in this context, just a no-op? > > Which part of the above would be a no-op? Exactly that: (set-file-extended-attributes buffer-file-name (file-extended-attributes buffer-file-name)) We set the extended file attributes on the same file (`buffer-file-name') where we just got them from (`buffer-file-name'). >> I fully understand that the extended attributes stored in `setmodes' are >> required later to restore the attributes of the file after it has been >> written to. And in that context I understand why we call >> `set-file-extended-attributes'. But here not really, yet. > > Well, then let me turn the table and ask you: why do you think we need > to restore the extended attributes later? what is the purpose of doing > that? To restore them after we (possibly) have made the file writable. Which we need to do a) when the call to `write-region' has failed (then in function `basic-save-buffer-2' itself), but also b) when the call has succeeded (then further up the stack in `basic-save-buffer'). Thanks for your patience!