4
4
import site
5
5
import os
6
6
import tempfile
7
+ import getpass
7
8
from pip .backwardcompat import get_python_lib
8
9
9
10
@@ -25,6 +26,24 @@ def virtualenv_no_global():
25
26
if running_under_virtualenv () and os .path .isfile (no_global_file ):
26
27
return True
27
28
29
+ def _get_build_prefix ():
30
+ """ Returns a safe build_prefix """
31
+ path = os .path .join (tempfile .gettempdir (), 'pip-build-%s' % \
32
+ getpass .getuser ())
33
+ if sys .platform == 'win32' :
34
+ return path
35
+ try :
36
+ os .mkdir (path )
37
+ except OSError :
38
+ fd = os .open (path , os .O_RDONLY )
39
+ stat = os .fstat (fd )
40
+ if os .getuid () != stat .st_uid :
41
+ print ("The temporary folder for building (%s) " % path +
42
+ "is not owned by your user!" )
43
+ print ("pip will not work until the temporary folder is " + \
44
+ "either deleted or owned by your user account." )
45
+ sys .exit (1 )
46
+ return path
28
47
29
48
if running_under_virtualenv ():
30
49
build_prefix = os .path .join (sys .prefix , 'build' )
@@ -33,7 +52,7 @@ def virtualenv_no_global():
33
52
# Use tempfile to create a temporary folder for build
34
53
# Note: we are NOT using mkdtemp so we can have a consistent build dir
35
54
# Note: using realpath due to tmp dirs on OSX being symlinks
36
- build_prefix = os .path .realpath (os . path . join ( tempfile . gettempdir (), 'pip-build' ))
55
+ build_prefix = os .path .realpath (_get_build_prefix ( ))
37
56
38
57
## FIXME: keep src in cwd for now (it is not a temporary folder)
39
58
try :
0 commit comments