bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#66546: 30.0.50; save-buffer to write-protected file without backup f


From: Eli Zaretskii
Subject: bug#66546: 30.0.50; save-buffer to write-protected file without backup fails
Date: Sun, 15 Oct 2023 15:12:49 +0300

> From: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
> Cc: 66546@debbugs.gnu.org
> Date: Sun, 15 Oct 2023 13:39:04 +0200
> 
> Eli Zaretskii <eliz@gnu.org> 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)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]