Subject: bug#39284: 27.0.60; wdired: change file permissions fails on tramp buffers

From: Tino Calancha <[email-masked]>
Date: Sat, 25 Jan 2020 22:45:30 +0100

emacs -Q /tmp -l wdired --eval '(setq wdired-allow-to-change-permissions t)'
M-! touch foo RET
g
;; re-visit Dired buffer as root
C-x d /sudo::/tmp RET
j foo RET
C-x C-q
;; change the permissions for foo
C-a C-f C-f C-f SPC
C-c C-c
;; It fails because it passes the wrong argument to the external chmod.

I propose 2 alternatives patches:

1) Assuming Bug#39280 is fixed, we just need to change 1 line ...:

--8<-----------------------------cut here---------------start------------->8---
commit 6c139e1582645d210f051e547609b524ef6d1ef6
Author: Tino Calancha <[email-masked]>
Date:   Sat Jan 25 19:53:20 2020 +0100

    Fix bug 39284
    
    * lisp/wdired.el (wdired-do-perm-changes)
    Call wdired-get-filename with non-nil.

diff --git a/lisp/wdired.el b/lisp/wdired.el
index 23dc4b9ef5..81071d40be 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -894,7 +894,7 @@ wdired-do-perm-changes
 		       (point) (next-single-property-change (point) 'end-perm)))
       (unless (equal perms-ori perms-new)
         (setq changes t)
-        (setq filename (wdired-get-filename nil t))
+        (setq filename (wdired-get-filename 'no-dir t))
         (if (= (length perms-new) 10)
             (progn
               (setq perm-tmp
--8<-----------------------------cut here---------------end--------------->8---

2) ... Or replace the call to the external chmod with built-in `set-file-modes'
(this is what `dired-do-chmod' does):

--8<-----------------------------cut here---------------start------------->8---
commit b2e6fc288e55919d54e27d24e478f7815d406514
Author: Tino Calancha <[email-masked]>
Date:   Sat Jan 25 22:27:08 2020 +0100

    Fix bug 39284
    
    * lisp/wdired.el (wdired-do-perm-changes)
    Use set-file-modes instead of external program.

diff --git a/lisp/wdired.el b/lisp/wdired.el
index d470e0a21b..34aa61f9ae 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -898,9 +898,8 @@ wdired-do-perm-changes
         (if (= (length perms-new) 10)
             (progn
               (setq perm-tmp
-                    (int-to-string (wdired-perms-to-number perms-new)))
-              (unless (equal 0 (process-file dired-chmod-program
-					     nil nil nil perm-tmp filename))
+                    (string-to-number (int-to-string (wdired-perms-to-number perms-new)) 8))
+              (unless (set-file-modes filename perm-tmp)
                 (setq errors (1+ errors))
                 (dired-log "%s %s `%s' failed\n\n"
                            dired-chmod-program perm-tmp filename)))

--8<-----------------------------cut here---------------end--------------->8---

In GNU Emacs 27.0.60 (build 28, x86_64-pc-linux-gnu, GTK+ Version 3.24.5)
 of 2020-01-25 built on calancha-pc.dy.bbexcite.jp
Repository revision: baca81e64141aed076fe088e7160f6e0d4a51c68
Repository branch: emacs-27
Windowing system distributor 'The X.Org Foundation', version 11.0.12004000
System Description: Debian GNU/Linux 10 (buster)

Recent messages:
Tramp: Waiting for prompts from remote shell...done
Tramp: Found remote shell prompt on ‘calancha-pc.dy.bbexcite.jp’
Tramp: Opening connection for [email-masked] using sudo...done
Directory has changed on disk; type g to update Dired
Mark set
Press C-c C-c when finished or C-c ESC to abort changes
C-c C-f is undefined
1 rename actions failed--type ? for details
d-elete, u-ndelete, x-punge, f-ind, o-ther window, R-ename, C-opy, h-elp
Tramp: Timeout session /sudo:[email-masked]: