From 82f38ce9a185e446f30c1089696a48c3f19e63de Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 17 Jun 2010 13:20:51 -0500 Subject: [PATCH] Allow with-*-group/user to be a no-op if first parameter is f --- basis/unix/groups/groups-docs.factor | 8 ++++---- basis/unix/groups/groups-tests.factor | 3 +++ basis/unix/groups/groups.factor | 10 ++++++++-- basis/unix/users/users-docs.factor | 8 ++++---- basis/unix/users/users-tests.factor | 3 +++ basis/unix/users/users.factor | 10 ++++++++-- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/basis/unix/groups/groups-docs.factor b/basis/unix/groups/groups-docs.factor index 3afe344d53..e75e320ab9 100644 --- a/basis/unix/groups/groups-docs.factor +++ b/basis/unix/groups/groups-docs.factor @@ -65,8 +65,8 @@ HELP: user-groups HELP: with-effective-group { $values - { "string/id" "a string or a group id" } { "quot" quotation } } -{ $description "Sets the effective group name and calls the quotation. Restors the effective group name on success or on error after the call." } ; + { "string/id/f" "a string, a group id, or f" } { "quot" quotation } } +{ $description "Sets the effective group name and calls the quotation. Restors the effective group name on success or on error after the call. If the first parameter is " { $link f } ", the quotation is called as the current user." } ; HELP: with-group-cache { $values @@ -75,8 +75,8 @@ HELP: with-group-cache HELP: with-real-group { $values - { "string/id" "a string or a group id" } { "quot" quotation } } -{ $description "Sets the real group name and calls the quotation. Restores the current group name on success or on error after the call." } ; + { "string/id/f" "a string or a group id" } { "quot" quotation } } +{ $description "Sets the real group name and calls the quotation. Restores the current group name on success or on error after the call. If the first parameter is " { $link f } ", the quotation is called as the current user." } ; ARTICLE: "unix.groups" "Unix groups" "The " { $vocab-link "unix.groups" } " vocabulary contains words that return information about Unix groups." diff --git a/basis/unix/groups/groups-tests.factor b/basis/unix/groups/groups-tests.factor index 7755be1d4d..bdb059cbca 100644 --- a/basis/unix/groups/groups-tests.factor +++ b/basis/unix/groups/groups-tests.factor @@ -28,3 +28,6 @@ IN: unix.groups.tests [ f ] [ "please-oh-please-don't-have-a-group-named-this123lalala" group-struct ] unit-test [ "please-oh-please-don't-have-a-group-named-this123lalala" ?group-id ] must-fail + +[ 3 ] [ f [ 3 ] with-effective-group ] unit-test +[ 3 ] [ f [ 3 ] with-real-group ] unit-test diff --git a/basis/unix/groups/groups.factor b/basis/unix/groups/groups.factor index 69c0ac0a00..e6eff0f6e1 100644 --- a/basis/unix/groups/groups.factor +++ b/basis/unix/groups/groups.factor @@ -109,14 +109,20 @@ GENERIC: set-real-group ( obj -- ) GENERIC: set-effective-group ( obj -- ) -: with-real-group ( string/id quot -- ) +: (with-real-group) ( string/id quot -- ) '[ _ set-real-group @ ] real-group-id '[ _ set-real-group ] [ ] cleanup ; inline -: with-effective-group ( string/id quot -- ) +: with-real-group ( string/id/f quot -- ) + over [ (with-real-group) ] [ nip call ] if ; inline + +: (with-effective-group) ( string/id quot -- ) '[ _ set-effective-group @ ] effective-group-id '[ _ set-effective-group ] [ ] cleanup ; inline +: with-effective-group ( string/id/f quot -- ) + over [ (with-effective-group) ] [ nip call ] if ; inline +