Browse files

Fix #725 and #729.

Signed-off-by: David <db@d1b.org>
  • Loading branch information...
1 parent c96548f commit eeaa64d25da3b030dd9459069eaf7d6109bf531d @d1b d1b committed Nov 23, 2012
Showing with 20 additions and 1 deletion.
  1. +20 −1 pip/locations.py
View
21 pip/locations.py
@@ -4,6 +4,7 @@
import site
import os
import tempfile
+import getpass
from pip.backwardcompat import get_python_lib
@@ -25,6 +26,24 @@ def virtualenv_no_global():
if running_under_virtualenv() and os.path.isfile(no_global_file):
return True
+def _get_build_prefix():
+ """ Returns a safe build_prefix """
+ path = os.path.join(tempfile.gettempdir(), 'pip-build-%s' % \
+ getpass.getuser())
+ if sys.platform == 'win32':
+ return path
+ try:
+ os.mkdir(path)
+ except OSError:
+ fd = os.open(path, os.O_RDONLY)
+ stat = os.fstat(fd)
+ if os.getuid() != stat.st_uid:
+ print ("The temporary folder for building (%s) " % path +
+ "is not owned by your user!")
+ print("pip will not work until the temporary folder is " + \
+ "either deleted or owned by your user account.")
+ sys.exit(1)
+ return path
if running_under_virtualenv():
build_prefix = os.path.join(sys.prefix, 'build')
@@ -33,7 +52,7 @@ def virtualenv_no_global():
# Use tempfile to create a temporary folder for build
# Note: we are NOT using mkdtemp so we can have a consistent build dir
# Note: using realpath due to tmp dirs on OSX being symlinks
- build_prefix = os.path.realpath(os.path.join(tempfile.gettempdir(), 'pip-build'))
+ build_prefix = os.path.realpath(_get_build_prefix())
## FIXME: keep src in cwd for now (it is not a temporary folder)
try:

0 comments on commit eeaa64d

Please sign in to comment.