From: Rob Browning Date: Sat, 29 Sep 2012 16:21:32 +0000 (-0500) Subject: Handle nonexistent groups in Metadata._apply_common_rec(). X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=6ddad71811edb38e56b35e20b1a2d5305c14015b;p=packages%2Fb%2Fbup.git Handle nonexistent groups in Metadata._apply_common_rec(). Thanks to Oei, Yung-Chin for tracking this down. Reported-by: Yung-Chin Signed-off-by: Rob Browning Reviewed-by: Zoran Zaric --- diff --git a/lib/bup/metadata.py b/lib/bup/metadata.py index dfb7438..58f2989 100644 --- a/lib/bup/metadata.py +++ b/lib/bup/metadata.py @@ -369,13 +369,13 @@ class Metadata: user_gids = os.getgroups() if self.gid in user_gids: gid = self.gid - if not restore_numeric_ids and \ - self.gid != 0 and \ - self.group in [grp_from_gid(x).gr_name for x in user_gids]: - try: - gid = grp_from_name(self.group).gr_gid - except KeyError: - pass # Fall back to gid. + if not restore_numeric_ids and self.gid != 0: + # The grp might not exist on the local system. + grps = filter(None, [grp_from_gid(x) for x in user_gids]) + if self.group in [x.gr_name for x in grps]: + g = grp_from_name(self.group) + if g: + gid = g.gr_gid if uid != -1 or gid != -1: try: