Skip to content

Commit eeaa64d

Browse files
committed
Fix pypa#725 and pypa#729.
Signed-off-by: David <[email protected]>
1 parent c96548f commit eeaa64d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

pip/locations.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import site
55
import os
66
import tempfile
7+
import getpass
78
from pip.backwardcompat import get_python_lib
89

910

@@ -25,6 +26,24 @@ def virtualenv_no_global():
2526
if running_under_virtualenv() and os.path.isfile(no_global_file):
2627
return True
2728

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
2847

2948
if running_under_virtualenv():
3049
build_prefix = os.path.join(sys.prefix, 'build')
@@ -33,7 +52,7 @@ def virtualenv_no_global():
3352
# Use tempfile to create a temporary folder for build
3453
# Note: we are NOT using mkdtemp so we can have a consistent build dir
3554
# 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())
3756

3857
## FIXME: keep src in cwd for now (it is not a temporary folder)
3958
try:

0 commit comments

Comments
 (0)