summaryrefslogtreecommitdiffstats
path: root/pym/portage_util.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-03-29 08:51:06 +0000
committerZac Medico <zmedico@gentoo.org>2006-03-29 08:51:06 +0000
commit97dab7de5fa1e17e544c64ca7f53eb229a1f14bc (patch)
treea38ab7f007bedf05c7c602cb8b5cb968e8c22232 /pym/portage_util.py
parent500944bbd59b52572cd5838871290015fccf0f6e (diff)
downloadportage-97dab7de5fa1e17e544c64ca7f53eb229a1f14bc.tar.gz
portage-97dab7de5fa1e17e544c64ca7f53eb229a1f14bc.tar.bz2
portage-97dab7de5fa1e17e544c64ca7f53eb229a1f14bc.zip
Automatically follow symlinks in the atomic_ofstream constructor. See bug #127897.
svn path=/main/trunk/; revision=3034
Diffstat (limited to 'pym/portage_util.py')
-rw-r--r--pym/portage_util.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/pym/portage_util.py b/pym/portage_util.py
index ae5312175..14ecaa7f8 100644
--- a/pym/portage_util.py
+++ b/pym/portage_util.py
@@ -607,9 +607,21 @@ class atomic_ofstream(file):
file when the write is interrupted (for example, when an 'out of space'
error occurs)."""
- def __init__(self, filename, mode='w', **kargs):
+ def __init__(self, filename, mode='w', follow_links=True, **kargs):
"""Opens a temporary filename.pid in the same directory as filename."""
self._aborted = False
+
+ if follow_links:
+ canonical_path = os.path.realpath(filename)
+ self._real_name = canonical_path
+ tmp_name = "%s.%i" % (canonical_path, os.getpid())
+ try:
+ super(atomic_ofstream, self).__init__(tmp_name, mode=mode, **kargs)
+ return
+ except (OSError, IOError), e:
+ writemsg("!!! Failed to open file: '%s'\n" % tmp_name)
+ writemsg("!!! %s\n" % str(e))
+
self._real_name = filename
tmp_name = "%s.%i" % (filename, os.getpid())
super(atomic_ofstream, self).__init__(tmp_name, mode=mode, **kargs)