mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
test: Don't use shell=True in lint-files.py
Avoid the use of shell=True.
This commit is contained in:
parent
85aea18ae6
commit
48d2e80a74
1 changed files with 8 additions and 7 deletions
|
@ -14,9 +14,10 @@ from subprocess import check_output
|
|||
from typing import Optional, NoReturn
|
||||
|
||||
CMD_TOP_LEVEL = ["git", "rev-parse", "--show-toplevel"]
|
||||
CMD_ALL_FILES = "git ls-files -z --full-name"
|
||||
CMD_SOURCE_FILES = 'git ls-files -z --full-name -- "*.[cC][pP][pP]" "*.[hH]" "*.[pP][yY]" "*.[sS][hH]"'
|
||||
CMD_SHEBANG_FILES = "git grep --full-name --line-number -I '^#!'"
|
||||
CMD_ALL_FILES = ["git", "ls-files", "-z", "--full-name"]
|
||||
CMD_SOURCE_FILES = ["git", "ls-files", "-z", "--full-name", "--", "*.[cC][pP][pP]", "*.[hH]", "*.[pP][yY]", "*.[sS][hH]"]
|
||||
CMD_SHEBANG_FILES = ["git", "grep", "--full-name", "--line-number", "-I", "^#!"]
|
||||
|
||||
ALLOWED_FILENAME_REGEXP = "^[a-zA-Z0-9/_.@][a-zA-Z0-9/_.@-]*$"
|
||||
ALLOWED_SOURCE_FILENAME_REGEXP = "^[a-z0-9_./-]+$"
|
||||
ALLOWED_SOURCE_FILENAME_EXCEPTION_REGEXP = (
|
||||
|
@ -73,7 +74,7 @@ def check_all_filenames() -> int:
|
|||
Checks every file in the repository against an allowed regexp to make sure only lowercase or uppercase
|
||||
alphanumerics (a-zA-Z0-9), underscores (_), hyphens (-), at (@) and dots (.) are used in repository filenames.
|
||||
"""
|
||||
filenames = check_output(CMD_ALL_FILES, shell=True).decode("utf8").rstrip("\0").split("\0")
|
||||
filenames = check_output(CMD_ALL_FILES).decode("utf8").rstrip("\0").split("\0")
|
||||
filename_regex = re.compile(ALLOWED_FILENAME_REGEXP)
|
||||
failed_tests = 0
|
||||
for filename in filenames:
|
||||
|
@ -92,7 +93,7 @@ def check_source_filenames() -> int:
|
|||
|
||||
Additionally there is an exception regexp for directories or files which are excepted from matching this regexp.
|
||||
"""
|
||||
filenames = check_output(CMD_SOURCE_FILES, shell=True).decode("utf8").rstrip("\0").split("\0")
|
||||
filenames = check_output(CMD_SOURCE_FILES).decode("utf8").rstrip("\0").split("\0")
|
||||
filename_regex = re.compile(ALLOWED_SOURCE_FILENAME_REGEXP)
|
||||
filename_exception_regex = re.compile(ALLOWED_SOURCE_FILENAME_EXCEPTION_REGEXP)
|
||||
failed_tests = 0
|
||||
|
@ -111,7 +112,7 @@ def check_all_file_permissions() -> int:
|
|||
|
||||
Additionally checks that for executable files, the file contains a shebang line
|
||||
"""
|
||||
filenames = check_output(CMD_ALL_FILES, shell=True).decode("utf8").rstrip("\0").split("\0")
|
||||
filenames = check_output(CMD_ALL_FILES).decode("utf8").rstrip("\0").split("\0")
|
||||
failed_tests = 0
|
||||
for filename in filenames:
|
||||
file_meta = FileMeta(filename)
|
||||
|
@ -156,7 +157,7 @@ def check_shebang_file_permissions() -> int:
|
|||
"""
|
||||
Checks every file that contains a shebang line to ensure it has an executable permission
|
||||
"""
|
||||
filenames = check_output(CMD_SHEBANG_FILES, shell=True).decode("utf8").strip().split("\n")
|
||||
filenames = check_output(CMD_SHEBANG_FILES).decode("utf8").strip().split("\n")
|
||||
|
||||
# The git grep command we use returns files which contain a shebang on any line within the file
|
||||
# so we need to filter the list to only files with the shebang on the first line
|
||||
|
|
Loading…
Add table
Reference in a new issue