Skip to content

Commit 61cc16d

Browse files
committed
Fix #725 and #729.
Signed-off-by: David <[email protected]>
1 parent 854574f commit 61cc16d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

pip/locations.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import shutil
77
import tempfile
8+
import getpass
89
from pip.backwardcompat import get_python_lib
910

1011

@@ -26,14 +27,32 @@ def virtualenv_no_global():
2627
if running_under_virtualenv() and os.path.isfile(no_global_file):
2728
return True
2829

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
2948

3049
if running_under_virtualenv():
3150
build_prefix = os.path.join(sys.prefix, 'build')
3251
src_prefix = os.path.join(sys.prefix, 'src')
3352
else:
3453
# Use tempfile to create a temporary folder for build
3554
# 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()
3756

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

0 commit comments

Comments
 (0)