Automatically follow symlinks in the atomic_ofstream constructor. See bug #127897.
authorZac Medico <zmedico@gentoo.org>
Wed, 29 Mar 2006 08:51:06 +0000 (08:51 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 29 Mar 2006 08:51:06 +0000 (08:51 -0000)
svn path=/main/trunk/; revision=3034

pym/portage_util.py

index ae5312175d104b2b2a51aa03adcd2152f501560f..14ecaa7f8dee26cb957bc6082cbec517e9635457 100644 (file)
@@ -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)