sbang.py: single lstat (#29670)
This commit is contained in:
parent
eda5b854a5
commit
80195bd1ed
@ -160,22 +160,20 @@ def filter_shebang(path):
|
|||||||
def filter_shebangs_in_directory(directory, filenames=None):
|
def filter_shebangs_in_directory(directory, filenames=None):
|
||||||
if filenames is None:
|
if filenames is None:
|
||||||
filenames = os.listdir(directory)
|
filenames = os.listdir(directory)
|
||||||
|
|
||||||
|
is_exe = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
|
||||||
|
|
||||||
for file in filenames:
|
for file in filenames:
|
||||||
path = os.path.join(directory, file)
|
path = os.path.join(directory, file)
|
||||||
|
|
||||||
# only handle files
|
# Only look at executable, non-symlink files.
|
||||||
if not os.path.isfile(path):
|
try:
|
||||||
|
st = os.lstat(path)
|
||||||
|
except (IOError, OSError):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# only handle executable files
|
if (stat.S_ISLNK(st.st_mode) or stat.S_ISDIR(st.st_mode) or
|
||||||
st = os.stat(path)
|
not st.st_mode & is_exe):
|
||||||
if not st.st_mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH):
|
|
||||||
continue
|
|
||||||
|
|
||||||
# only handle links that resolve within THIS package's prefix.
|
|
||||||
if os.path.islink(path):
|
|
||||||
real_path = os.path.realpath(path)
|
|
||||||
if not real_path.startswith(directory + os.sep):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# test the file for a long shebang, and filter
|
# test the file for a long shebang, and filter
|
||||||
|
Loading…
Reference in New Issue
Block a user