1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-07 04:10:27 -08:00

Use connection-aware functions when getting the UID/GID in Eshell

This means, for example, that when using Tramp to sudo in Eshell, "rm"
queries the user before deleting anything (bug#63221).

* lisp/eshell/esh-util.el (eshell-user-login-name): New function...
* lisp/eshell/em-unix.el (eshell/whoami): ... use it.

* lisp/eshell/em-ls.el (eshell-ls-applicable): Use 'file-user-uid' and
'eshell-user-login-name'.
(eshell-ls-decorated-name): Use 'file-user-uid'.

* lisp/eshell/em-pred.el (eshell-predicate-alist): Use 'file-user-uid'
and 'file-group-gid'.

* lisp/eshell/em-unix.el (eshell-interactive-query): New widget...
(eshell-rm-interactive-query, eshell-mv-interactive-query)
(eshell-cp-interactive-query, eshell-ln-interactive-query): ... use
it.
(eshell-interactive-query-p): New function...
(eshell/rm, eshell/mv, eshell/cp, eshell/ln): ... use it.

* lisp/simple.el (file-group-gid): New function.

* lisp/net/ange-ftp.el (ange-ftp-file-group-gid): New function...
(file-group-gid): ... use it.

* lisp/net/tramp.el (tramp-handle-file-group-gid):
* lisp/net/tramp-archive.el (tramp-archive-handle-file-group-gid): New
functions.

* lisp/net/tramp.el (tramp-file-name-for-operation): Add
'file-group-gid'.

* lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist):
* lisp/net/tramp-archive.el (tramp-archive-file-name-handler-alist):
* lisp/net/tramp-crypt.el (tramp-crypt-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):
* lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist):
Add 'file-group-gid' mapping.

* test/lisp/net/tramp-tests.el (tramp-test44-file-user-group-ids):
* test/lisp/net/tramp-archive-tests.el
(tramp-archive-test44-file-user-group-ids): Add tests for
'file-group-gid'.

* doc/lispref/files.texi (Magic File Names): Mention 'file-group-gid'.

* doc/lispref/os.texi (User Identification): Document
'file-group-gid', and move 'group-real-gid' to match the order of
'user-real-uid'.

* etc/NEWS: Announce 'file-group-gid'.
This commit is contained in:
Jim Porter 2023-05-01 09:49:00 -07:00
parent fa33a14ebe
commit 40d6609563
21 changed files with 143 additions and 44 deletions

View file

@ -881,16 +881,18 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
(zerop (nth 1 fsi))
(zerop (nth 2 fsi))))))
;; `file-user-uid' was introduced in Emacs 30.1.
(ert-deftest tramp-archive-test44-file-user-uid ()
;; `file-user-uid' and `file-group-gid' were introduced in Emacs 30.1.
(ert-deftest tramp-archive-test44-user-group-ids ()
"Check that `file-user-uid' returns proper values."
(skip-unless tramp-archive-enabled)
(skip-unless (fboundp 'file-user-uid))
(skip-unless (and (fboundp 'file-user-uid)
(fboundp 'file-group-gid)))
(let ((default-directory tramp-archive-test-archive))
;; `file-user-uid' exists since Emacs 30.1. We don't want to see
;; compiler warnings for older Emacsen.
(should (integerp (with-no-warnings (file-user-uid))))))
;; `file-user-uid' and `file-group-gid' exist since Emacs 30.1.
;; We don't want to see compiler warnings for older Emacsen.
(should (integerp (with-no-warnings (file-user-uid))))
(should (integerp (with-no-warnings (file-group-gid))))))
(ert-deftest tramp-archive-test48-auto-load ()
"Check that `tramp-archive' autoloads properly."

View file

@ -7367,16 +7367,20 @@ This requires restrictions of file name syntax."
(dotimes (i (length fsi))
(should (natnump (or (nth i fsi) 0))))))
;; `file-user-uid' was introduced in Emacs 30.1.
(ert-deftest tramp-test44-file-user-uid ()
"Check that `file-user-uid' and `tramp-get-remote-*' return proper values."
;; `file-user-uid' and `file-group-gid' were introduced in Emacs 30.1.
(ert-deftest tramp-test44-file-user-group-ids ()
"Check results of user/group functions.
`file-user-uid', `file-group-gid', and `tramp-get-remote-*'
should all return proper values."
(skip-unless (tramp--test-enabled))
(let ((default-directory ert-remote-temporary-file-directory))
;; `file-user-uid' exists since Emacs 30.1. We don't want to see
;; compiler warnings for older Emacsen.
;; `file-user-uid' and `file-group-gid' exist since Emacs 30.1.
;; We don't want to see compiler warnings for older Emacsen.
(when (fboundp 'file-user-uid)
(should (integerp (with-no-warnings (file-user-uid)))))
(when (fboundp 'file-group-gid)
(should (integerp (with-no-warnings (file-group-gid)))))
(with-parsed-tramp-file-name default-directory nil
(should (or (integerp (tramp-get-remote-uid v 'integer))