Subject: Re: bug#78638: 30.1; When editing a remote file owned by another user, Tramp signals an error because it cannot change the file mode

From: Eli Zaretskii <[email-masked]>
Date: Sun, 15 Jun 2025 17:08:48 +0300

> From: Michael Albinus <[email-masked]>
> Cc: Paul Eggert <[email-masked]>,  [email-masked],
>   [email-masked]
> Date: Sun, 15 Jun 2025 15:50:54 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> Hi Eli,
> 
> >> Line 6309 in files.el:
> >> 
> >> --8<---------------cut here---------------start------------->8---
> >>                 (write-region nil nil
> >>                               buffer-file-name nil t buffer-file-truename)
> >> --8<---------------cut here---------------end--------------->8---
> >> 
> >> And the error is raised in line 5536 of fileio.c:
> >> 
> >> --8<---------------cut here---------------start------------->8---
> >> (gdb) n
> >> 5536		  report_file_errno ("Opening output file", filename, open_errno);
> >
> > Thanks.  Is this with backup-by-copying = t or nil?  Also, does the
> > file /tmp/xxx exist at this point with the original owner and modes
> > before you edited and saved it?
> 
> I've started 'emacs -Q', so it is the default: nil
> 
> And yes, it is still the file owned by another user:
> 
> --8<---------------cut here---------------start------------->8---
> # ll /tmp/xxx
> -rw-rw----. 1 testuser1 albinus 0 Jun 15 09:17 /tmp/xxx
> --8<---------------cut here---------------end--------------->8---

Thanks.

So the problem is not with saving the edited buffer, the problem is
that backup-file doesn't work for some reason in this case.  Does
setting backup-by-copying non-nil solve the problem?

If not, then (as I don't have access to a system where I can do "sudo
useradd"), would it be possible for you to step through the code in
backup-buffer, and tell which part there fails and why, both with
backup-by-copying set to nil and non-nil?