From 005959bbe9998185bf9600387aa308ffabba0070 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sat, 19 Mar 2022 17:52:55 -0700 Subject: [PATCH 3/3] Add 'G' argument predicate in Eshell * lisp/eshell/em-pred.el (eshell-predicate-alist): Add 'G' predicate. (eshell-predicate-help-string): Document it. * test/lisp/eshell/em-pred-tests.el (em-pred-test/predicate-effective-gid): New test. * doc/misc/eshell.text (Argument Predication): Document 'G' predicate. --- doc/misc/eshell.texi | 3 +++ lisp/eshell/em-pred.el | 9 +++++---- test/lisp/eshell/em-pred-tests.el | 8 ++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi index 2b49ddb03c..89f5b953f5 100644 --- a/doc/misc/eshell.texi +++ b/doc/misc/eshell.texi @@ -1266,6 +1266,9 @@ Argument Predicates @item @code{U} Matches files owned by the current effective user ID. +@item @code{G} +Matches files owned by the current effective group ID. + @item @code{l@option{[+-]}@var{n}} Matches files with @var{n} links. With @option{+} (or @option{-}), matches files with more than (or less than) @var{n} links, diff --git a/lisp/eshell/em-pred.el b/lisp/eshell/em-pred.el index 8afc86dd41..eb5109b82d 100644 --- a/lisp/eshell/em-pred.el +++ b/lisp/eshell/em-pred.el @@ -88,10 +88,10 @@ eshell-predicate-alist (if (file-exists-p file) (= (file-attribute-user-id (file-attributes file)) (user-uid))))) - ;; (?G . (lambda (file) ; owned by effective gid - ;; (if (file-exists-p file) - ;; (= (file-attribute-user-id (file-attributes file)) - ;; (user-uid))))) + (?G . (lambda (file) ; owned by effective gid + (if (file-exists-p file) + (= (file-attribute-group-id (file-attributes file)) + (group-gid))))) (?* . (lambda (file) (and (file-regular-p file) (not (file-symlink-p file)) @@ -161,6 +161,7 @@ eshell-predicate-help-string OWNERSHIP: U owned by effective uid + G owned by effective gid u(UID|\\='user\\=') owned by UID/user g(GID|\\='group\\=') owned by GID/group diff --git a/test/lisp/eshell/em-pred-tests.el b/test/lisp/eshell/em-pred-tests.el index 74dad9f8b8..fbf8945215 100644 --- a/test/lisp/eshell/em-pred-tests.el +++ b/test/lisp/eshell/em-pred-tests.el @@ -225,6 +225,14 @@ em-pred-test/predicate-effective-uid (should (equal (eshell-eval-predicate files "U") '("/fake/uid=1"))))))) +(ert-deftest em-pred-test/predicate-effective-gid () + "Test that \"G\" matches files owned by the effective GID." + (eshell-with-file-attributes-from-name + (cl-letf (((symbol-function 'group-gid) (lambda () 1))) + (let ((files '("/fake/gid=1" "/fake/gid=2"))) + (should (equal (eshell-eval-predicate files "G") + '("/fake/gid=1"))))))) + (ert-deftest em-pred-test/predicate-links () "Test that \"l\" filters by number of links." (eshell-with-file-attributes-from-name -- 2.25.1