From 484fc70a7acc5a958bfeefa4b83255680c7da175 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 16 Oct 2023 14:17:57 +0300 Subject: [PATCH] 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) --- lisp/files.el | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index e1421b403bf..adfe8bd44b9 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -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) -- 2.39.2