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: Wed, 18 Oct 2023 22:36:04 +0200 Message-ID: <87sf671xe3.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> <87ttqpgg8l.fsf@sappc2.fritz.box> <83cyxcnp2f.fsf@gnu.org> Reply-To: Jens Schmidt Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15917"; 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 Wed Oct 18 22:36:51 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 1qtDHd-0003vK-Lg for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 18 Oct 2023 22:36:49 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtDHS-0004TV-3f; Wed, 18 Oct 2023 16:36:38 -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 1qtDHQ-0004SO-QP for bug-gnu-emacs@gnu.org; Wed, 18 Oct 2023 16:36:36 -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 1qtDHQ-0000Py-Hx for bug-gnu-emacs@gnu.org; Wed, 18 Oct 2023 16:36:36 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qtDHq-0005Zc-BC for bug-gnu-emacs@gnu.org; Wed, 18 Oct 2023 16:37: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: Wed, 18 Oct 2023 20:37: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.169766141221407 (code B ref 66546); Wed, 18 Oct 2023 20:37:02 +0000 Original-Received: (at 66546) by debbugs.gnu.org; 18 Oct 2023 20:36:52 +0000 Original-Received: from localhost ([127.0.0.1]:34739 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtDHg-0005ZC-5W for submit@debbugs.gnu.org; Wed, 18 Oct 2023 16:36:52 -0400 Original-Received: from mr3.vodafonemail.de ([145.253.228.163]:46824) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtDHc-0005Yv-Hf for 66546@debbugs.gnu.org; Wed, 18 Oct 2023 16:36:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vodafonemail.de; s=vfde-mb-mr2-23sep; t=1697661375; bh=FzLMsuZpYs2BdCP6GItk6tr9EizCS7rpdvUWshRKZmk=; h=From:To:Subject:References:Date:In-Reply-To:Message-ID:User-Agent: Content-Type:From; b=FNBqWHad4rpdcTrsIqKKQhWaTZFYB0ZI5vXPqtwHSDmz5BKlq1qEauxEz3LGm2cOb KDi7mvJf817QYc3jKBcgOocP8kdIo156DZBTICHBH4MmdVParr40Ob/GdJ7lSCI5/j xBkETTvio4brPwVkZquywJNH4qAT6YRALgMvQNgA= 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 mr3.vodafonemail.de (Postfix) with ESMTPS id 4S9jL74LNTz1yjM; Wed, 18 Oct 2023 20:36:15 +0000 (UTC) Original-Received: from sappc2 (port-92-194-247-250.dynamic.as20676.net [92.194.247.250]) (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 4S9jL020llzMm5T; Wed, 18 Oct 2023 20:36:05 +0000 (UTC) In-Reply-To: <83cyxcnp2f.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 18 Oct 2023 14:32:40 +0300") X-purgate-type: clean X-purgate: clean X-purgate-size: 3357 X-purgate-ID: 155817::1697661371-F1FFB228-76B82ECB/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:272684 Archived-At: Eli Zaretskii writes: >> From: Jens Schmidt >> Cc: 66546@debbugs.gnu.org >> Date: Tue, 17 Oct 2023 22:12:58 +0200 >> >> Eli Zaretskii writes: >> >> Do we agree that this bug is all about the "no-backup" case (*C-0* C-x >> C-s)? > > The bug is, but basic-save-buffer-2 isn't. > >> 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. > > While true, I'm not sure what does this have to do with the issue we > are discussing. > >> 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. > > Only if this condition in basic-save-buffer-2 is NOT true: > > [...] > > Again, I'm not sure why is this relevant. All of the above is relevant, at least for me, and I'm glad that we agree up to your corrections, which make sense. > I think you have an inaccurate mental model of what > set-file-extended-attributes does. In particular, you seem to think > that > > (set-file-extended-attributes > buffer-file-name > (file-extended-attributes buffer-file-name)) > > leaves the file with the same unchanged extended attributes, as if it > were a set-file-modes call. But that is not true in general, > especially if the original owner of the file was not the same user as > the one who runs the Emacs session that makes these calls. Depending > on the OS, the actual privileges of the user running Emacs, and the > file-access setup of the underlying system, the user might not be > allowed to set some of the attributes, or might become the owner of > the file, or the OS could add some extended attributes to the original > ones. So the above is not necessarily a no-op, although in simple > cases it probably is. I see, thanks. The one thing I still do not understand is, however: Why exactly do we need that (set-file-extended-attributes buffer-file-name (file-extended-attributes buffer-file-name)) incantation or the equivalent one (setq setmodes (list (file-modes buffer-file-name) (with-demoted-errors "Error getting extended attributes: %s" (file-extended-attributes buffer-file-name)) buffer-file-name)) (with-demoted-errors "Error setting attributes: %s" (set-file-extended-attributes buffer-file-name (nth 1 setmodes))) in function `basic-save-buffer-2'? That doesn't seem to be a common pattern. There are a few hits for `set-file-extended-attributes' in the Emacs sources, but they all attempt to transfer (as far as the OS allows) attributes from one file to a different one. In addition, I tried to trace back (this time hopefully correctly) the origin of this call to `set-file-extended-attributes' and reached this commit: 574c05e21947 Karel Kl=C3=ADc - Add SELinux support. Karel added as comment on this function: (basic-save-buffer-2): Set SELinux context of the newly created file, and return it. But we do not have a "newly created file" here, and, in my opinion, do not need to set an SELinux context/extended attributes on it.