Subject: 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: Sun, 15 Jun 2025 12:55:38 +0200

Eli Zaretskii <[email-masked]> writes:

Hi Eli,

>> Cc: [email-masked], [email-masked]
>> Date: Sun, 15 Jun 2025 11:16:35 +0300
>> From: Eli Zaretskii <[email-masked]>
>> 
>> > --8<---------------cut here---------------start------------->8---
>> > basic-save-buffer-2: Opening output file: Permission denied, /tmp/xxx
>> > --8<---------------cut here---------------end--------------->8---
>> 
>> Thanks.  Can I ask you to show a Lisp backtrace from this error?
>
> Actually, what is interesting is the line of basic-save-buffer-2 which
> signaled the error.  Is it possible for you to figure that out?

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);
(gdb) bt
#0  write_region (start=<optimized out>, end=<optimized out>, filename=0x9c9364, append=0x0, visit=<optimized out>, lockname=0x1302a84, mustbenew=<optimized out>, desc=-1) at fileio.c:5536
#1  0x000000000058438f in Fwrite_region (start=<optimized out>, end=<optimized out>, filename=<optimized out>, append=<optimized out>, visit=<optimized out>, lockname=<optimized out>, mustbenew=0x0) at fileio.c:5383
#2  0x00000000005d0b3b in funcall_subr (subr=<optimized out>, numargs=<optimized out>, args=<optimized out>) at eval.c:3231
#3  0x00000000005d2817 in Ffuncall (nargs=<optimized out>, args=0x7fffffffd798) at eval.c:3151
#4  0x00007ffff0c08ed4 in F62617369632d736176652d6275666665722d32_basic_save_buffer_2_0 () at /home/albinus/src/emacs/src/../native-lisp/31.0.50-289b8565/preloaded/files-1e8937b2-7dcbec5d.eln
#5  0x00000000005d2817 in Ffuncall (nargs=<optimized out>, args=0x7fffffffd830) at eval.c:3151
#6  0x00007ffff0c083e9 in F62617369632d736176652d6275666665722d31_basic_save_buffer_1_0 () at /home/albinus/src/emacs/src/../native-lisp/31.0.50-289b8565/preloaded/files-1e8937b2-7dcbec5d.eln
#7  0x00000000005d2817 in Ffuncall (nargs=<optimized out>, args=0x7fffffffd8d8) at eval.c:3151
#8  0x00007ffff0c07afd in F62617369632d736176652d627566666572_basic_save_buffer_0 () at /home/albinus/src/emacs/src/../native-lisp/31.0.50-289b8565/preloaded/files-1e8937b2-7dcbec5d.eln
#9  0x00000000005d2817 in Ffuncall (nargs=<optimized out>, args=0x7fffffffd970) at eval.c:3151
#10 0x00007ffff0c06faf in F736176652d627566666572_save_buffer_0 () at /home/albinus/src/emacs/src/../native-lisp/31.0.50-289b8565/preloaded/files-1e8937b2-7dcbec5d.eln
#11 0x00000000005d2817 in Ffuncall (nargs=nargs@entry=2, args=args@entry=0x7fffffffda58) at eval.c:3151
#12 0x00000000005cb244 in Ffuncall_interactively (nargs=2, args=0x7fffffffda58) at callint.c:250
#13 0x00000000005d2817 in Ffuncall (nargs=nargs@entry=3, args=args@entry=0x7fffffffda50) at eval.c:3151
#14 0x00000000005cbbde in Fcall_interactively (function=<optimized out>, record_flag=<optimized out>, keys=<optimized out>) at callint.c:789
#15 0x00007ffff0aa31e5 in F636f6d6d616e642d65786563757465_command_execute_0 () at /home/albinus/src/emacs/src/../native-lisp/31.0.50-289b8565/preloaded/simple-fab5b0cf-9e866eaa.eln
#16 0x00000000005d2817 in Ffuncall (nargs=nargs@entry=2, args=args@entry=0x7fffffffdd40) at eval.c:3151
#17 0x0000000000554924 in command_loop_1 () at keyboard.c:1545
#18 0x00000000005cde34 in internal_condition_case (bfun=bfun@entry=0x554550 <command_loop_1>, handlers=handlers@entry=0x90, hfun=hfun@entry=0x5474d0 <cmd_error>) at eval.c:1684
#19 0x000000000053f242 in command_loop_2 (handlers=0x90) at keyboard.c:1163
#20 0x00000000005cdd8e in internal_catch (tag=tag@entry=0x125d0, func=func@entry=0x53f220 <command_loop_2>, arg=arg@entry=0x90) at eval.c:1364
#21 0x000000000053f1df in command_loop () at keyboard.c:1141
#22 0x0000000000547081 in recursive_edit_1 () at keyboard.c:749
#23 0x000000000054740e in Frecursive_edit () at keyboard.c:832
#24 0x0000000000411c06 in main (argc=3, argv=<optimized out>) at emacs.c:2582

Lisp Backtrace:
"write-region" (0xffffd7a0)
"basic-save-buffer-2" (0xffffd838)
"basic-save-buffer-1" (0xffffd8e0)
"basic-save-buffer" (0xffffd978)
"save-buffer" (0xffffda60)
"funcall-interactively" (0xffffda58)
"command-execute" (0xffffdd48)
(gdb) 
--8<---------------cut here---------------end--------------->8---

Best regards, Michael.