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

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

bug#44627: 25.2; tempsetmodes handling does not update extended attribut


From: Lars Ingebrigtsen
Subject: bug#44627: 25.2; tempsetmodes handling does not update extended attributes
Date: Tue, 07 Jun 2022 12:44:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Michael Young <mwy-hsyzfo@the-youngs.org> writes:

> Open a read-only file, toggle read-only mode, and modify the file.
> Attempt to save the file.
> Answer "yes" to the prompt
>   File <FILENAME> is write-protected; try to save anyway? (yes or no)
>
> If the filesystem housing <FILENAME> supports extended attributes,
> the attempt to temporarily change the file mode doesn't do anything,
> and the subsequent attempt to write fails in basic-save-buffer-2:
>     Opening output file: Permission denied, <FILENAME>
>
> This section of files.el appears to be the problem:
>     
> https://github.com/emacs-mirror/emacs/blob/d408866ff2a0de7af5d8bb40d9c1c310573f1800/lisp/files.el#L5444
>
> It retrieves the extended attributes, but then does not make any changes
> to them before setting them.  If the attempt to set the extended
> attributes fails, it falls back on set-file-modes to set the
> POSIX user write permission (128) -- that appears to work as intended.

(I'm going through old bug reports that unfortunately weren't resolved
at the time.)

This bug report is about Emacs 25.2, but the code is still essentially
the same today:

        ;; 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.
        (cond ((and tempsetmodes (not setmodes))
               ;; Change the mode back, after writing.
               (setq setmodes (list (file-modes buffer-file-name)
                                    (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)))
                 (set-file-modes buffer-file-name
                                 (logior (car setmodes) 128)))))

I.e., it's reading the extended attributes -- and then setting the
extended attributes to exactly what they were, which seems nonsensical.
Is this anything but a NOOP on any system?

For this to work, Emacs would have to (as Michael points out) actually
modify the extended attributes to allow writing, but does Emacs have any
functions to do that?  A brief poke around doesn't seem to reveal
anything -- anybody know?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





reply via email to

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