[rhinstaller/anaconda/pulls/448 master] Allow a user's primary group to be created in --groups (#1279041)

vpodzime installerbot-noreply at redhat.com
Wed Nov 11 08:22:54 UTC 2015


> @@ -270,10 +270,23 @@ def createUser(self, user_name, *args, **kwargs):
>  
>          args = ["-R", root]
>  
> -        # If a specific gid is requested, and that gid does not exist,
> -        # create the user group with that GID.
> +        # Split the groups argument into a list of (username, gid or None) tuples
> +        # the gid, if any, is a string since that makes things simpler
> +        group_gids = [GROUPLIST_FANCY_PARSE.match(group).groups()
> +                      for group in kwargs.get("groups", [])]
> +
> +        # If a specific gid is requested:
> +        #   - check if a group already exists with that GID. i.e., the user's
> +        #     GID should refer to a system group, such as users. If so, just set
> +        #     the GID.
> +        #   - check if a new group is requested with that GID. If so, set the GID
> +        #     and let the block below create the actual group.
> +        #   - if neither of those are true, create a new user group with the requested
> +        #     GID
> +        # otherwise use -U to create a new user group with the next available GID.
>          if kwargs.get("gid", None):
> -            if not self._getgrgid(kwargs['gid'], root):
> +            if not self._getgrgid(kwargs['gid'], root) and \
> +                    not any(filter(lambda x: x[1] == str(kwargs['gid']), group_gids)):

Could be a matter of personal preferences, but I really like this more:
``any(gid[1] == str(kwargs['gid']) for gid in group_gids)``

(and it should do the same, AFAICT)

-- 
To view this pull request on github, visit https://github.com/rhinstaller/anaconda/pull/448#discussion_r44510436


More information about the anaconda-patches mailing list