From: David James Date: Wed, 21 Jul 2010 01:28:54 +0000 (+0000) Subject: Fix race condition in Portage symlink creation. X-Git-Tag: v2.2_rc68~449 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=33be46793e851e19d2c250522e85a0f4d4034ef8;p=portage.git Fix race condition in Portage symlink creation. --- diff --git a/pym/portage/util/movefile.py b/pym/portage/util/movefile.py index 298d15186..f8cc695fb 100644 --- a/pym/portage/util/movefile.py +++ b/pym/portage/util/movefile.py @@ -80,10 +80,18 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, target=target[len(mysettings["D"]):] if destexists and not stat.S_ISDIR(dstat[stat.ST_MODE]): os.unlink(dest) - if selinux_enabled: - selinux.symlink(target, dest, src) - else: - os.symlink(target,dest) + try: + if selinux_enabled: + selinux.symlink(target, dest, src) + else: + os.symlink(target, dest) + except OSError as e: + # Some programs will create symlinks automatically, so we have + # to tolerate these links being recreated during the merge + # process. In any case, if the link is pointing at the right + # place, we're in good shape. + if e.errno != errno.ENOENT or target != os.readlink(dest): + raise lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID]) # utime() only works on the target of a symlink, so it's not # possible to perserve mtime on symlinks.