summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid James <davidjames@google.com>2010-07-21 01:28:54 +0000
committerZac Medico <zmedico@gentoo.org>2010-07-26 23:24:23 -0700
commit33be46793e851e19d2c250522e85a0f4d4034ef8 (patch)
treecf1dc2e53acefdb34f5f95ef2968f67b4ae6cdb9
parentFix ExtendedAtomDict so get() and __getitem__() behave consistently, (diff)
downloadportage-multirepo-33be46793e851e19d2c250522e85a0f4d4034ef8.tar.gz
portage-multirepo-33be46793e851e19d2c250522e85a0f4d4034ef8.tar.bz2
portage-multirepo-33be46793e851e19d2c250522e85a0f4d4034ef8.zip
Fix race condition in Portage symlink creation.
-rw-r--r--pym/portage/util/movefile.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/pym/portage/util/movefile.py b/pym/portage/util/movefile.py
index 298d1518..f8cc695f 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.