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: Michael Albinus <[email-masked]>
Date: Thu, 12 Jun 2025 12:24:48 +0200

Michael McClennen <[email-masked]> writes:

> Hello Michael,

Hi Michael,

> I have done as you asked. Here are the steps I took, in detail:
>
> 1. Run emacs with the arguments listed below.
> 2. Hit c-x c-f.
> 3. Opened the file
> “/scp:taphonomy:/var/paleobiodb/frontend/pbdb-app/collections/collections.html”.
> The file is owned by somebody else, but its mode bits allow me to edit
> it.

Hmm. The file has the attributes:

--8<---------------cut here---------------start------------->8---
18:07:21.527949 tramp-send-command (6) # tramp_stat_file_attributes /var/paleobiodb/frontend/pbdb-app/collections/collections.html 2>/dev/null; echo tramp_exit_status $?
18:07:21.589164 tramp-wait-for-regexp (6) #
(("‘/var/paleobiodb/frontend/pbdb-app/collections/collections.html’") 1 ("bnoushin7" . 29012) ("pbdb" . 1000) 1749680914 1749680900 1749680900 84008 "-rw-rw-r--" t 1847394 -1)
--8<---------------cut here---------------end--------------->8---

Your remote identity is:

--8<---------------cut here---------------start------------->8---
18:07:21.758801 tramp-send-command (6) # /bin/id
18:07:21.824346 tramp-wait-for-regexp (6) #
uid=1000(mmcclenn) gid=1000(pbdb) groups=1000(pbdb),119(docker),22999(sudo_passwd)
--8<---------------cut here---------------end--------------->8---

So indeed, the group id "pbdb" should be sufficient for editing. After
saving your edits, the used local temporary file is copied to remote:

--8<---------------cut here---------------start------------->8---
18:07:40.213573 tramp-do-copy-or-rename-file-out-of-band (6) # scp -T -q -r -o ControlMaster=auto -o ControlPath=tramp.%C -o ControlPersist=no /var/folders/rd/94y9m04x2v1cttshz_mprjdr0000gp/T/tramp.NtIfrx.html taphonomy:/var/paleobiodb/frontend/pbdb-app/collections/collections.html
--8<---------------cut here---------------end--------------->8---

This succeeds. However, the next step, changing the file mode of the
copied file fails. And this is reported as error:

--8<---------------cut here---------------start------------->8---
18:07:40.559966 tramp-send-command (6) # chmod  664 /var/paleobiodb/frontend/pbdb-app/collections/collections.html 2>/dev/null; echo tramp_exit_status $?
18:07:40.626488 tramp-wait-for-regexp (6) #
tramp_exit_status 1
18:07:40.627115 tramp-barf-unless-okay (1) # File error: Error while changing file’s mode /scp:taphonomy:/var/paleobiodb/frontend/pbdb-app/collections/collections.html
--8<---------------cut here---------------end--------------->8---

But the file has a changed modification time (1749683260) and size
(84009), which is proper:

--8<---------------cut here---------------start------------->8---
18:08:45.246430 tramp-send-command (6) # tramp_stat_file_attributes /var/paleobiodb/frontend/pbdb-app/collections/collections.html 2>/dev/null; echo tramp_exit_status $?
18:08:45.307161 tramp-wait-for-regexp (6) #
(("‘/var/paleobiodb/frontend/pbdb-app/collections/collections.html’") 1 ("bnoushin7" . 29012) ("pbdb" . 1000) 1749680914 1749683260 1749683260 84009 "-rw-rw-r--" t 1847394 -1)
--8<---------------cut here---------------end--------------->8---

So the chmod command fails.

Since Emacs 30.1, there is the user option
tramp-inhibit-errors-if-setting-file-attributes-fail. See (info "(tramp)
Frequently Asked Questions")

--8<---------------cut here---------------start------------->8---
   • How to ignore errors when changing file attributes?

     Sometimes, for example while saving remote files, errors appear
     when changing file attributes like permissions, time stamps, or
     ownership.  If these errors can be ignored, set user option
     ‘tramp-inhibit-errors-if-setting-file-attributes-fail’ to a
     non-‘nil’ value.  This transforms the error into a warning.
--8<---------------cut here---------------end--------------->8---

> I hope this helps. Thank you for responding to this issue!
>
>   — Michael McClennen

Best regards, Michael.