diff --git a/news/6364.bugfix b/news/6364.bugfix new file mode 100644 index 00000000000..4a659751f6e --- /dev/null +++ b/news/6364.bugfix @@ -0,0 +1 @@ +Correctly set executable permissions in cases where /tmp is mounted 'noexec.' diff --git a/src/pip/_internal/operations/install/wheel.py b/src/pip/_internal/operations/install/wheel.py index b1a76a24ce2..d181ef1c9f2 100644 --- a/src/pip/_internal/operations/install/wheel.py +++ b/src/pip/_internal/operations/install/wheel.py @@ -398,9 +398,13 @@ def clobber( os.utime(destfile, (st.st_atime, st.st_mtime)) # If our file is executable, then make our destination file - # executable. - if os.access(srcfile, os.X_OK): - st = os.stat(srcfile) + # executable. Account for cases where the tmpdir + # is mounted 'noexec'; we make the destination executable + # if any -x flags are set on srcfile rather than using + # os.access(), which will always return False if srcfile + # is in a directory mounted 'noexec.' + st = os.stat(srcfile) + if st.st_mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH): permissions = ( st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH )