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: Fri, 20 Oct 2023 09:06:35 +0300 Message-ID: <835y31u8t0.fsf@gnu.org> 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> <87ttqpgg8l.fsf@sappc2.fritz.box> <83cyxcnp2f.fsf@gnu.org> <87sf671xe3.fsf@sappc2.fritz.box> <83y1fzmdhm.fsf@gnu.org> <87zg0ez57o.fsf@sappc2.fritz.box> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13101"; 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 Fri Oct 20 08:07:59 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 1qtifu-0003Dd-GM for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 20 Oct 2023 08:07:58 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtifm-0007Cs-Su; Fri, 20 Oct 2023 02:07:50 -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 1qtifk-0007Cb-E3 for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2023 02:07:49 -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 1qtifi-00030R-8G for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2023 02:07:47 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qtify-00029n-6I for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2023 02:08: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: Fri, 20 Oct 2023 06:08: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.16977820368232 (code B ref 66546); Fri, 20 Oct 2023 06:08:02 +0000 Original-Received: (at 66546) by debbugs.gnu.org; 20 Oct 2023 06:07:16 +0000 Original-Received: from localhost ([127.0.0.1]:38482 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtifE-00028g-7R for submit@debbugs.gnu.org; Fri, 20 Oct 2023 02:07:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48632) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtifC-00028Q-QE for 66546@debbugs.gnu.org; Fri, 20 Oct 2023 02:07:15 -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 1qtief-0002s5-7u; Fri, 20 Oct 2023 02:06:41 -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=mz5TtO8EY/lZprliRDFmQAtyHvcaAXZEj9fvFm050xM=; b=AhWuEt4aoktc vEm6fVhSvGfhTEKjsku2aYZMOyWnsvTKzxnNQGPhrAKJBU2jBMHBtu9/WHvrSsCA1gfzJsP9WZ9kF wFBtJLwrRuM5cwaaNsfxAEUOG1HJlHwu9PQrTde+/snxS9IhvAM+Na77Kx89Yvfsp9+zL7YOQ+Lw2 lNzxPzXOw+I535LROPV8wCUFN/hNFeCyrddEmu7TZbDdslonMjRYwU06kBNa4cCFCov/BJ4276l/M NbHBD4ijh7u9NsOvlN138Y8J1rzOYm2D2Z4VV/oggpaT07teaj7x5lWRtg0KOu891AN0A8uSf6etU UOCb0nimX4dcPTpOo37KXA==; In-Reply-To: <87zg0ez57o.fsf@sappc2.fritz.box> (message from Jens Schmidt on Thu, 19 Oct 2023 23:12:59 +0200) 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:272773 Archived-At: > From: Jens Schmidt > Cc: 66546@debbugs.gnu.org > Date: Thu, 19 Oct 2023 23:12:59 +0200 > > But probably it would be helpful to shortcut that look-up process, like > this: > > @@ -5946,7 +5949,9 @@ basic-save-buffer-2 > (file-extended-attributes buffer-file-name)) > buffer-file-name)) > ;; If set-file-extended-attributes fails to make the > - ;; file writable, fall back on set-file-modes. > + ;; file writable, fall back on set-file-modes. Calling > + ;; set-file-extended-attributes here may or may not be > + ;; actually necessary, for details see Bug#66546. > (with-demoted-errors "Error setting attributes: %s" > (set-file-extended-attributes buffer-file-name > (nth 1 setmodes))) I don't object, though a more detailed explanation (instead of sending people to read the bug discussion) would be better. > + ;; If we get an error writing the file which we > + ;; previously made writable, attempt to undo the > + ;; write-access. > + ((and (eq tempsetmodes 'u+w) (not success)) Isn't it easier, safer, and more portable to compare buffer-file-name with (nth 2 setmodes) instead? > + (condition-case () > + (unless > + (with-demoted-errors "Error setting file modes: %S" > + (set-file-modes buffer-file-name (car setmodes))) > + (set-file-extended-attributes buffer-file-name > + (nth 1 setmodes))) > + (error nil))) Why do we need condition-case here if we use with-demoted-errors? > I also attached a slightly unrelated, minor doc fix I came across > when working on this bug. Thanks, installed on the emacs-29 branch (with minor changes in the commit log message).