File tree 1 file changed +20
-1
lines changed 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 5
5
import os
6
6
import shutil
7
7
import tempfile
8
+ import getpass
8
9
from pip .backwardcompat import get_python_lib
9
10
10
11
@@ -26,14 +27,32 @@ def virtualenv_no_global():
26
27
if running_under_virtualenv () and os .path .isfile (no_global_file ):
27
28
return True
28
29
30
+ def _get_build_prefix ():
31
+ """ Returns a safe build_prefix """
32
+ path = os .path .join (tempfile .gettempdir (), 'pip-build-%s' % \
33
+ getpass .getuser ())
34
+ if sys .platform == 'win32' :
35
+ return path
36
+ try :
37
+ os .mkdir (path )
38
+ except OSError :
39
+ fd = os .open (path , os .O_RDONLY )
40
+ stat = os .fstat (fd )
41
+ if os .getuid () != stat .st_uid :
42
+ print ("The temporary folder for building (%s) " % path +
43
+ "is not owned by your user!" )
44
+ print ("pip will not work until the temporary folder is " + \
45
+ "either deleted or owned by your user account." )
46
+ sys .exit (1 )
47
+ return path
29
48
30
49
if running_under_virtualenv ():
31
50
build_prefix = os .path .join (sys .prefix , 'build' )
32
51
src_prefix = os .path .join (sys .prefix , 'src' )
33
52
else :
34
53
# Use tempfile to create a temporary folder for build
35
54
# Note: we are NOT using mkdtemp so we can have a consistent build dir
36
- build_prefix = os . path . join ( tempfile . gettempdir (), 'pip-build' )
55
+ build_prefix = _get_build_prefix ( )
37
56
38
57
## FIXME: keep src in cwd for now (it is not a temporary folder)
39
58
try :
You can’t perform that action at this time.
0 commit comments