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: Sat, 14 Oct 2023 22:31:36 +0200 Message-ID: <8734ydx7x3.fsf@sappc2.fritz.box> References: <83h6mtq9t7.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="4146"; 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 Sat Oct 14 22:33:04 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 1qrlJn-0000sK-Co for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 14 Oct 2023 22:33:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrlJU-0004vC-Dn; Sat, 14 Oct 2023 16:32:44 -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 1qrlJP-0004tt-3F for bug-gnu-emacs@gnu.org; Sat, 14 Oct 2023 16:32:39 -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 1qrlJO-0002gz-Qz for bug-gnu-emacs@gnu.org; Sat, 14 Oct 2023 16:32:38 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qrlJm-0001Dl-I1 for bug-gnu-emacs@gnu.org; Sat, 14 Oct 2023 16:33: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: Sat, 14 Oct 2023 20:33: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.16973155404621 (code B ref 66546); Sat, 14 Oct 2023 20:33:02 +0000 Original-Received: (at 66546) by debbugs.gnu.org; 14 Oct 2023 20:32:20 +0000 Original-Received: from localhost ([127.0.0.1]:50705 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qrlJ6-0001CT-1Y for submit@debbugs.gnu.org; Sat, 14 Oct 2023 16:32:20 -0400 Original-Received: from mr6.vodafonemail.de ([145.253.228.166]:39154) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qrlJ3-0001CD-Np for 66546@debbugs.gnu.org; Sat, 14 Oct 2023 16:32:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vodafonemail.de; s=vfde-mb-mr2-21dec; t=1697315508; bh=SBz3G2VJ60P1us6b/q1M72LvpRorYBgK7ACz8UWVKr0=; h=From:To:Subject:References:Date:In-Reply-To:Message-ID:User-Agent: Content-Type:From; b=T8BMiGI7TCguJ/Yy3YNiH1sBO0NIzfEOOPSdwMdYrPvsUkgsBkjfz9fBv4WT2BYzI kRTWUz5knMjD1yMK13YbxVEJFVuTWa1KYRInquNrUGqAoug4igr+ArhgK+raLVtDQL spoxjttfvP4yNP14fdwJnxcSKq/eWRWP4aHHXvfA= 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 mr6.vodafonemail.de (Postfix) with ESMTPS id 4S7FQq6tkyz1xxc; Sat, 14 Oct 2023 20:31:47 +0000 (UTC) Original-Received: from sappc2 (port-92-194-107-54.dynamic.as20676.net [92.194.107.54]) (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 4S7FQh2CKcz9s4d; Sat, 14 Oct 2023 20:31:37 +0000 (UTC) In-Reply-To: <83h6mtq9t7.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 14 Oct 2023 22:32:36 +0300") X-purgate-type: clean X-purgate: clean X-purgate-size: 3732 X-purgate-ID: 155817::1697315503-7A7F9E22-121443DC/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:272471 Archived-At: Eli Zaretskii writes: >> Eli, sorry to disturb you with another edge-case bug, but the commit >> that has introduced it was yours > > It wasn't. Sorry, I misread the annotation. Thanks for looking into this, anyway. >> *** Issue A >> >> In a shell execute: >> >> echo foo > foo >> chmod 0400 foo >> ./src/emacs -Q foo >> C-x C-q >> bar >> C-0 C-x C-s >> => File foo is write-protected; try to save anyway? >> yes RET >> => basic-save-buffer-2: Opening output file: Permission denied, >> /home/jschmidt/work/emacs-master/foo >> >> When saving *with* backup, that is, without prefix C-0, everything works >> as expected: The file temporarily gets write permissions, gets written >> to, and write permissions get removed again. > > Please explain what happens with "C-0 C-x C-s", and why. I don't > think I understand that, given what you wrote. "C-0 C-x C-s" prompts me whether to write the modified buffer to the write-protected file. When I reply "yes", I expect Emacs to do the following: 1. Get the mode bits/extended attributes of "foo". 2. Remove the write-potection on "foo". 3. Write the buffer to "foo", not creating a backup file. 4. Restore the mode bits/extended attributes on "foo" to their previous state taken in step 1. What happens instead: Emacs errors out that it cannot write to the file, even though it has the permissions and means to temporarily remove the write-protection on it. >> The marked call [1] is a no-op, since it does not change the permissions >> in any way when writing them back, while the call [2] to >> `set-file-modes' actually changes the file mode. > > set-file-modes is supposed to be called only if > set-file-extended-attributes fails, unless my reading of the code is > incorrect. So again, I don't follow. Please ignore that bit, since my wording used there is indeed not quite clear. What I really wanted to express is explained below, hopefully clearer now. >> Since an extended file attribute Elisp object cannot be modified yet (is >> that so?) to mark it, for example, as writable, > > What do you mean by that? I mean that in an ideal world, my fix for this issue would have looked like this: ------------------------- snip ------------------------- diff --git a/lisp/files.el b/lisp/files.el index e1421b403bf..47245c43bd5 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5948,8 +5948,9 @@ basic-save-buffer-2 ;; set-file-modes. (unless (with-demoted-errors "Error setting attributes: %s" - (set-file-extended-attributes buffer-file-name - (nth 1 setmodes))) + (set-file-extended-attributes + buffer-file-name + (make-exattr-writable (nth 1 setmodes)))) (set-file-modes buffer-file-name (logior (car setmodes) 128))))) (let (success) ------------------------- snip ------------------------- where I invented a function `make-exattr-writable' that takes the Elisp encapsulation of extended file attributes and modifies it such, that when it is applied to a file again, the file is then writable. Just as it happens with the traditional `set-file-modes' call through the `(logior OLD-MODE 128)'. >> I propose to just drop that call to `set-file-extended-attributes', >> like this: > > Why does it make sense to ignore the extended attributes here, when we > don't ignore them elsewhere in Emacs? Because we do not have the equivalent to `(logior OLD-MODE 128)' for extended attributes yet. Or do we?