diff options
| author | Michael Albinus <michael.albinus@gmx.de> | 2018-12-16 15:49:07 +0100 |
|---|---|---|
| committer | Michael Albinus <michael.albinus@gmx.de> | 2018-12-16 15:49:07 +0100 |
| commit | e8199e765f81968be840d8e7e3978f5974c1be9d (patch) | |
| tree | 354c9b7af9c126a49e614b716225c49135d702b4 /lisp/net/tramp-sh.el | |
| parent | 4f230e8dd551d711433e2a8095a19c2ce00c9b4c (diff) | |
| download | emacs-e8199e765f81968be840d8e7e3978f5974c1be9d.tar.gz | |
Add Tramp sudoedit method
* doc/misc/tramp.texi (Quick Start Guide): New section "Using sudoedit".
(External methods) <sudoedit>: Describe.
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist):
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist):
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist):
* lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist)
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist):
Add handler.
* lisp/net/tramp-sh.el (tramp-sh-handle-set-file-uid-gid): Rename from
`tramp-sh-handle-set-file-uid-gid'. Handle only remote file names.
* lisp/net/tramp-sudoedit.el: New file.
* lisp/net/tramp.el (tramp-file-name-for-operation): Handle also
`tramp-set-file-uid-gid'.
(tramp-set-file-uid-gid): New defun.
(tramp-get-local-uid, tramp-get-local-gid): Cache result.
* test/lisp/net/tramp-tests.el (tramp--test-sudoedit-p): New defun.
(tramp-test20-file-modes, tramp-test22-file-times)
(tramp--test-sudoedit-p): Use it.
Diffstat (limited to 'lisp/net/tramp-sh.el')
| -rw-r--r-- | lisp/net/tramp-sh.el | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index a6e9d299a87..a3038780e6c 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -1044,6 +1044,7 @@ of command line.") (start-file-process . tramp-sh-handle-start-file-process) (substitute-in-file-name . tramp-handle-substitute-in-file-name) (temporary-file-directory . tramp-handle-temporary-file-directory) + (tramp-set-file-uid-gid . tramp-sh-handle-set-file-uid-gid) (unhandled-file-name-directory . ignore) (vc-registered . tramp-sh-handle-vc-registered) (verify-visited-file-modtime . tramp-sh-handle-verify-visited-file-modtime) @@ -1516,39 +1517,26 @@ of." "") (tramp-shell-quote-argument localname))))))) -(defun tramp-set-file-uid-gid (filename &optional uid gid) - "Set the ownership for FILENAME. -If UID and GID are provided, these values are used; otherwise uid -and gid of the corresponding user is taken. Both parameters must -be non-negative integers." +(defun tramp-sh-handle-set-file-uid-gid (filename &optional uid gid) + "Like `tramp-set-file-uid-gid' for Tramp files." ;; Modern Unices allow chown only for root. So we might need ;; another implementation, see `dired-do-chown'. OTOH, it is mostly ;; working with su(do)? when it is needed, so it shall succeed in ;; the majority of cases. ;; Don't modify `last-coding-system-used' by accident. (let ((last-coding-system-used last-coding-system-used)) - (if (tramp-tramp-file-p filename) - (with-parsed-tramp-file-name filename nil - (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 (natnump uid) uid) - (tramp-get-remote-uid v 'integer))) - (gid (or (and (natnump 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" does not work. - (unless (memq system-type '(ms-dos windows-nt)) - (let ((uid (or (and (natnump uid) uid) (tramp-get-local-uid 'integer))) - (gid (or (and (natnump gid) gid) (tramp-get-local-gid 'integer)))) - (tramp-call-process - nil "chown" nil nil nil - (format "%d:%d" uid gid) (shell-quote-argument filename))))))) + (with-parsed-tramp-file-name filename nil + (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 (natnump uid) uid) + (tramp-get-remote-uid v 'integer))) + (gid (or (and (natnump gid) gid) + (tramp-get-remote-gid v 'integer)))) + (tramp-send-command + v (format + "chown %d:%d %s" uid gid + (tramp-shell-quote-argument localname)))))))) (defun tramp-remote-selinux-p (vec) "Check, whether SELINUX is enabled on the remote host." @@ -2114,6 +2102,7 @@ file names." ;; Handle `preserve-extended-attributes'. We ignore possible ;; errors, because ACL strings could be incompatible. + ;; `set-file-extended-attributes' exists since Emacs 24.4. (when attributes (ignore-errors (apply 'set-file-extended-attributes (list newname attributes)))) |
