From 327e8ac4971bbb4681d00ce4b2df8dbce8848c0b Mon Sep 17 00:00:00 2001
From: Michael Albinus <michael.albinus@gmx.de>
Date: Tue, 30 Jun 2009 12:10:36 +0000
Subject: [PATCH] * net/tramp.el (tramp-do-copy-or-rename-file-directly):
 Handle also the 'rename case, when setting file modes.  (Bug#3712)

---
 lisp/ChangeLog    | 7 ++++++-
 lisp/net/tramp.el | 8 +++++---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7fc927008ee..bf5ef0bdd7b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,9 +1,14 @@
+2009-06-30  Michael Albinus  <michael.albinus@gmx.de>
+
+	* net/tramp.el (tramp-do-copy-or-rename-file-directly): Handle
+	also the 'rename case, when setting file modes.  (Bug#3712)
+
 2009-06-29  Alan Mackenzie  <acm@muc.de>
 
 	* progmodes/cc-cmds.el (c-mask-paragraph): Remove a spurious
 	correction between the visible width of TABs and their number of
 	bytes.
-	
+
 2009-06-29  Michael Albinus  <michael.albinus@gmx.de>
 
 	* net/tramp.el (tramp-do-copy-or-rename-file-directly): Set file
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index fdc1e276994..cf1f866cb2c 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3199,7 +3199,9 @@ KEEP-DATE means to make sure that NEWNAME has the same timestamp
 as FILENAME.  PRESERVE-UID-GID, when non-nil, instructs to keep
 the uid and gid from FILENAME."
   (let ((t1 (tramp-tramp-file-p filename))
-	(t2 (tramp-tramp-file-p newname)))
+	(t2 (tramp-tramp-file-p newname))
+	(file-times (nth 5 (file-attributes filename)))
+	(file-modes (tramp-default-file-modes filename)))
     (with-parsed-tramp-file-name (if t1 filename newname) nil
       (let* ((cmd (cond ((and (eq op 'copy) preserve-uid-gid) "cp -f -p")
 			((eq op 'copy) "cp -f")
@@ -3338,8 +3340,8 @@ the uid and gid from FILENAME."
       ;; Set the time and mode. Mask possible errors.
       (condition-case nil
 	  (when keep-date
-	    (set-file-times newname (nth 5 (file-attributes filename)))
-	    (set-file-modes newname (tramp-default-file-modes filename)))
+	    (set-file-times newname file-times)
+	    (set-file-modes newname file-modes))
 	(error)))))
 
 (defun tramp-do-copy-or-rename-file-out-of-band (op filename newname keep-date)
-- 
2.39.5