1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-26 07:33:47 +00:00

Fix "C-0 C-x C-s" with write-protected files

* lisp/files.el (basic-save-buffer-2): Call 'set-file-modes' to
try to make the file writable, even if
'set-file-extended-attributes' succeeded.  (Bug#66546)
This commit is contained in:
Eli Zaretskii 2023-10-16 14:17:57 +03:00
parent c3038bf5e1
commit 484fc70a7a

View File

@ -5933,9 +5933,10 @@ Before and after saving the buffer, this function runs
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 @@ Before and after saving the buffer, this function runs
"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)