diff -ruP mock-autocache-diff/mock.py mock-autocache-permfix/mock.py --- mock-autocache-diff/mock.py 2006-05-16 23:19:18.000000000 -0500 +++ mock-autocache-permfix/mock.py 2006-05-19 14:57:50.000000000 -0500 @@ -644,11 +644,39 @@ fo.close() def _make_our_user(self): + if not os.path.exists(os.path.join(self.rootdir, 'usr/sbin/useradd')): + raise RootError, "Could not find useradd in chroot, maybe the install failed?" # should check if the user exists first # make the buildusers/groups + need_add_user = 0 if not os.path.exists(self.rootdir + self.homedir): - if not os.path.exists(os.path.join(self.rootdir, 'usr/sbin/useradd')): - raise RootError, "Could not find useradd in chroot, maybe the install failed?" + need_add_user = 1 + else: + # check for the following conditions: + # -- using cache and current user is different from original cache creator + # -- using --no-clean and current user is different from original creator + curruid = self.config['chrootuid'] + chrootuid = None + passwd = os.path.join(self.rootdir, 'etc', 'passwd') + + # find UID used to set up buildroot + fd = open( passwd, "r" ) + while 1: + line = fd.readline() + if line == "": break + if line.startswith(self.config["chrootuser"]): + chrootuid = int(line.split(":")[2]) + + # do fixups if they are different + # if uid is different, assume we need to fix gid also + if chrootuid is not None and curruid != chrootuid: + need_add_user = 1 + self.do_chroot('/usr/sbin/userdel -r %s' % self.config["chrootuser"], fatal = False) + self.do_chroot('/usr/sbin/groupdel %s' % self.config["chrootgroup"], fatal = False) + self.do_chroot('chown -R %s.%s %s' % (self.config["chrootuid"], self.config["chrootgid"], self.config["chroothome"]), fatal = False) + # may need a few other chown here if there are other files that have to be edited + + if need_add_user: cmd = '/usr/sbin/useradd -m -u %s -d %s %s' % (self.config['chrootuid'], self.homedir, self.config['chrootuser']) self.do_chroot(cmd, fatal = True)