[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: |
Jens Schmidt |
Subject: |
bug#66546: 30.0.50; save-buffer to write-protected file without backup fails |
Date: |
Sun, 15 Oct 2023 11:34:17 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
>> Cc: 66546@debbugs.gnu.org
>> Date: Sat, 14 Oct 2023 22:31:36 +0200
>>
>> > Please explain what happens with "C-0 C-x C-s", and why. I don't
>> > think I understand that, given what you wrote.
>>
>> "C-0 C-x C-s" prompts me whether to write the modified buffer to the
>> write-protected file. When I reply "yes", I expect Emacs to do the
>> following:
>>
>> 1. Get the mode bits/extended attributes of "foo".
>> 2. Remove the write-potection on "foo".
>> 3. Write the buffer to "foo", not creating a backup file.
>> 4. Restore the mode bits/extended attributes on "foo" to their previous
>> state taken in step 1.
>
> So far, so good.
>
>> What happens instead:
>>
>> Emacs errors out that it cannot write to the file, even though it has
>> the permissions and means to temporarily remove the write-protection on
>> it.
>
> Why cannot Emacs write to the file, and what do the extended
> attributes have to do with that?
Let's check the working Emacs 23 code first, when there were no extended
attributes:
(setq setmodes (cons (file-modes buffer-file-name) buffer-file-name))
(set-file-modes buffer-file-name (logior (car setmodes) 128))
In procedural pseudo-code and without the cons, this does:
setmodes = file-modes (buffer-file-name);
set-file-modes (buffer-file-name, setmodes | 128);
which implements step 2 above: It takes the existing mode bits, adds bit
0b10000000 (u+w), and sets the resulting mode bits on the file. The
file gets writable. The following call to `write-region' succeeds.
Now the Emacs 29 code. We simplify that in the assumption, that the
extended attribute calls always succeed, and that we do not need the
regular calls:
(setq setmodes (list (file-extended-attributes buffer-file-name)
buffer-file-name))
(set-file-extended-attributes buffer-file-name
(nth 0 setmodes))
The pseudo-code here looks like this:
setmodes = file-extended-attributes (buffer-file-name);
set-file-extended-attributes (setmodes);
That is, the original extended attributes of the file get written back
to the file *unchanged*. No write permission is added to the file.
Accordingly, the following call to `write-region' fails.
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Jens Schmidt, 2023/10/14
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Eli Zaretskii, 2023/10/14
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Jens Schmidt, 2023/10/14
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Eli Zaretskii, 2023/10/15
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails,
Jens Schmidt <=
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Eli Zaretskii, 2023/10/15
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Jens Schmidt, 2023/10/15
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Eli Zaretskii, 2023/10/15
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Jens Schmidt, 2023/10/15
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Eli Zaretskii, 2023/10/16
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Jens Schmidt, 2023/10/16
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Eli Zaretskii, 2023/10/17
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Jens Schmidt, 2023/10/17
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Eli Zaretskii, 2023/10/18
- bug#66546: 30.0.50; save-buffer to write-protected file without backup fails, Jens Schmidt, 2023/10/18