changeset 103782:c5225871ee78

* net/tramp.el (tramp-set-file-uid-gid): Handle the case the remote user is root, on the local host. (tramp-local-host-p): Either the local user or the remote user must be root.
author Michael Albinus <michael.albinus@gmx.de>
date Wed, 08 Jul 2009 12:40:58 +0000
parents 455b21d42672
children d13837374d17
files lisp/net/tramp.el
diffstat 1 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/net/tramp.el	Wed Jul 08 07:23:55 2009 +0000
+++ b/lisp/net/tramp.el	Wed Jul 08 12:40:58 2009 +0000
@@ -2709,14 +2709,17 @@
   ;; the majority of cases.
   (if (file-remote-p filename)
       (with-parsed-tramp-file-name filename nil
-	(let ((uid (or (and (integerp uid) uid)
-		       (tramp-get-remote-uid v 'integer)))
-	      (gid (or (and (integerp gid) gid)
-		       (tramp-get-remote-gid v 'integer))))
-	  (tramp-send-command
-	   v (format
-	      "chown %d:%d %s" uid gid
-	      (tramp-shell-quote-argument localname)))))
+	(if (and (zerop (user-uid)) (tramp-local-host-p v))
+	    ;; If we are root on the local host, we can do it directly.
+	    (tramp-set-file-uid-gid localname uid gid)
+	  (let ((uid (or (and (integerp uid) uid)
+			 (tramp-get-remote-uid v 'integer)))
+		(gid (or (and (integerp gid) gid)
+			 (tramp-get-remote-gid v 'integer))))
+	    (tramp-send-command
+	     v (format
+		"chown %d:%d %s" uid gid
+		(tramp-shell-quote-argument localname))))))
 
     ;; We handle also the local part, because there doesn't exist
     ;; `set-file-uid-gid'.  On W32 "chown" might not work.
@@ -4395,7 +4398,7 @@
 		   (tramp-get-remote-gid v 'integer))))
 
       (if (and (tramp-local-host-p v)
-	       ;; `file-writable-p' calls 'file-expand-file-name'.  We
+	       ;; `file-writable-p' calls `file-expand-file-name'.  We
 	       ;; cannot use `tramp-run-real-handler' therefore.
 	       (let (file-name-handler-alist)
 		 (and
@@ -4403,10 +4406,10 @@
 		  (or (file-directory-p localname)
 		      (file-writable-p localname)))))
 	  ;; Short track: if we are on the local host, we can run directly.
-	  (prog1
-	      (tramp-run-real-handler
-	       'write-region
-	       (list start end localname append 'no-message lockname confirm))
+	  (progn
+	    (tramp-run-real-handler
+	     'write-region
+	     (list start end localname append 'no-message lockname confirm))
 	    (tramp-flush-file-property v localname))
 
 	(let ((rem-dec (tramp-get-remote-coding v "remote-decoding"))
@@ -7190,7 +7193,10 @@
        (tramp-file-name-method vec)
        (tramp-file-name-user vec)
        host
-       (tramp-compat-temporary-file-directory))))))
+       (tramp-compat-temporary-file-directory)))
+     ;; On some systems, chown runs only for root.
+     (or (zerop (user-uid))
+	 (zerop (tramp-get-remote-uid vec 'integer))))))
 
 ;; Variables local to connection.