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: Sun, 15 Oct 2023 15:12:49 +0300 Message-ID: <83pm1gozi6.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> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10101"; 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 Sun Oct 15 14:13:52 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 1qs00F-0002T8-Ur for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 15 Oct 2023 14:13:52 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qs003-0000bx-Ty; Sun, 15 Oct 2023 08:13:39 -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 1qs002-0000bm-D9 for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 08:13:38 -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 1qs002-0003sC-4z for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 08:13:38 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qs00P-0003rH-QT for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2023 08:14:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Oct 2023 12:14:01 +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.169737202014795 (code B ref 66546); Sun, 15 Oct 2023 12:14:01 +0000 Original-Received: (at 66546) by debbugs.gnu.org; 15 Oct 2023 12:13:40 +0000 Original-Received: from localhost ([127.0.0.1]:51384 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qs004-0003qY-AL for submit@debbugs.gnu.org; Sun, 15 Oct 2023 08:13:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41230) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qs000-0003qG-HA for 66546@debbugs.gnu.org; Sun, 15 Oct 2023 08:13:39 -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 1qrzzW-0003n0-LJ; Sun, 15 Oct 2023 08:13:06 -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=/UjHMR62JPit99TX8XKPY4KHzCfG7M1bzBnFGsvNyVU=; b=YuN/4UkF2XQh GQyfM0LQ26zkJY3oQrnq8pKkYHutzHPu3HRntY1tQ/BasYftX3UEZ0Rl2km3DWYHm5T9LUe7hpZhh HSPeXlTdzw8a7LcW4KDcpd6NUGvsqZ3KS3Jjn+iAy6nHyYKY/NFuj+Z9V7yLX1uMKYWsIIxjgF2C/ zTdLLdWhmhSs1dVFmnOSyaLIGbPAHbYIaoPt6+OVCJr8fArC7vPdUaZJoPj8VJu7meysJ565I+AkD o7gl4KGFJQ9RwmRa6Ax4IgMmoWJvX9xfn2I2pW8qd/bYGB4tursL58MZyOp8fKFhGu/EmOMVdb72C bomWH6mNbnoFhkosycF4rw==; In-Reply-To: <87il78cdyf.fsf@sappc2.fritz.box> (message from Jens Schmidt on Sun, 15 Oct 2023 13:39:04 +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:272506 Archived-At: > From: Jens Schmidt > Cc: 66546@debbugs.gnu.org > Date: Sun, 15 Oct 2023 13:39:04 +0200 > > Eli Zaretskii writes: > > > But I think I can guess what you wanted to say: you wanted to say that > > set-file-modes is called _only_ if set-file-extended-attributes fails, > > and it doesn't fail in this scenario. Is that what you wanted to say? > > Yes! Thanks for guessing :-) > > And I have been asking a related question implicitly in the previous > conversation, so here is it explicitly: In that case, does the change below fix the original problem? > Using *only* the extended-attribute Elisp functions and objects, is > there currently a way to implement the equivalent of "chmod u+w FILE" in > Elisp? AFAIU, this question has no meaningful answer. Extended attributes are much more fine-grained than the "traditional" file mode bits; in particular, they are incompatible with the "user" notion to fit the "u" part of "u+w": the same file can be writable by a specific user or group of users, and unwritable by others. Even if you only limit yourself to Posix extended attributes (and Emacs doesn't limit itself to that), there's no good answer to your question. diff --git a/lisp/files.el b/lisp/files.el index e1421b4..adfe8bd 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5933,9 +5933,10 @@ basic-save-buffer-2 buffer-file-name) t)) ;; If file not writable, see if we can make it writable - ;; temporarily while we write it. - ;; But no need to do so if we have just backed it up - ;; (setmodes is set) because that says we're superseding. + ;; temporarily while we write it (its original modes will be + ;; restored in 'basic-save-buffer'). But no need to do so if + ;; we have just backed it up (setmodes is set) because that + ;; says we're superseding. (cond ((and tempsetmodes (not setmodes)) ;; Change the mode back, after writing. (setq setmodes @@ -5944,12 +5945,12 @@ basic-save-buffer-2 "Error getting extended attributes: %s" (file-extended-attributes buffer-file-name)) buffer-file-name)) - ;; If set-file-extended-attributes fails, fall back on - ;; set-file-modes. - (unless - (with-demoted-errors "Error setting attributes: %s" - (set-file-extended-attributes buffer-file-name - (nth 1 setmodes))) + ;; If set-file-extended-attributes fails to make the + ;; file writable, fall back on set-file-modes. + (with-demoted-errors "Error setting attributes: %s" + (set-file-extended-attributes buffer-file-name + (nth 1 setmodes))) + (unless (file-writable-p buffer-file-name) (set-file-modes buffer-file-name (logior (car setmodes) 128))))) (let (success)