'Set owner of targetpath according to tarinfo.'

def chown(self, tarinfo, targetpath):

    if (pwd and hasattr(os, 'geteuid') and (os.geteuid() == 0)):
        try:
            g = grp.getgrnam(tarinfo.gname)[2]
        except KeyError:
            g = tarinfo.gid
        try:
            u = pwd.getpwnam(tarinfo.uname)[2]
        except KeyError:
            u = tarinfo.uid
        try:
            if (tarinfo.issym() and hasattr(os, 'lchown')):
                os.lchown(targetpath, u, g)
            elif (sys.platform != 'os2emx'):
                os.chown(targetpath, u, g)
        except EnvironmentError as e:
            raise ExtractError('could    not    change    owner')
