Use PORTAGE_TMPDIR if necessary for usersync.
authorZac Medico <zmedico@gentoo.org>
Thu, 7 Oct 2010 15:57:23 +0000 (08:57 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 7 Oct 2010 16:09:58 +0000 (09:09 -0700)
Bug #340046 - Don't require PORTAGE_TMPDIR access for --sync unless
it's really necessary.

pym/_emerge/actions.py

index 1866cf9c07c00fc44110180ff229899b735a3158..c768edd13cd5005f85529f378470d487011d01d7 100644 (file)
@@ -1884,12 +1884,6 @@ def action_sync(settings, trees, mtimedb, myopts, myaction):
                os.makedirs(myportdir,0o755)
                st = os.stat(myportdir)
 
-       # PORTAGE_TMPDIR is used below, so validate it and
-       # bail out if necessary.
-       rval = _check_temp_dir(settings)
-       if rval != os.EX_OK:
-               return rval
-
        usersync_uid = None
        spawn_kwargs = {}
        spawn_kwargs["env"] = settings.environ()
@@ -1914,6 +1908,13 @@ def action_sync(settings, trees, mtimedb, myopts, myaction):
                                umask = umask | 0o020
                        spawn_kwargs["umask"] = umask
 
+       if usersync_uid is not None:
+               # PORTAGE_TMPDIR is used below, so validate it and
+               # bail out if necessary.
+               rval = _check_temp_dir(settings)
+               if rval != os.EX_OK:
+                       return rval
+
        syncuri = settings.get("SYNC", "").strip()
        if not syncuri:
                writemsg_level("!!! SYNC is undefined. " + \
@@ -2173,8 +2174,13 @@ def action_sync(settings, trees, mtimedb, myopts, myaction):
                                # user. We assume that PORTAGE_TMPDIR will satisfy this
                                # requirement, since that's not necessarily true for the
                                # default directory used by the tempfile module.
+                               if usersync_uid is not None:
+                                       tmpdir = settings['PORTAGE_TMPDIR']
+                               else:
+                                       # use default dir from tempfile module
+                                       tmpdir = None
                                fd, tmpservertimestampfile = \
-                                       tempfile.mkstemp(dir=settings['PORTAGE_TMPDIR'])
+                                       tempfile.mkstemp(dir=tmpdir)
                                os.close(fd)
                                if usersync_uid is not None:
                                        portage.util.apply_permissions(tmpservertimestampfile,