mirror of
https://github.com/Tencent/MMKV.git
synced 2026-10-16 20:21:12 +08:00
Update formatCode.py
做了以下几处改动: 1.使用了 os.path.join() 拼接路径,确保跨平台兼容性 2.使用了 subprocess.run() 替代 os.system(),避免被包含特殊字符的路径进行注入攻击
This commit is contained in:
@@ -3,13 +3,15 @@
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import subprocess
|
||||
path = os.getcwd()
|
||||
|
||||
excluded_directories = ["pybind11", "/openssl", "/zlib", "/build/generated/", "cmake-build-debug/", "cmake-build-release", "CMakeFiles"]
|
||||
for root, dirs, files in os.walk(path):
|
||||
if (root.find("pybind11") != -1) or root.endswith("/openssl") or root.endswith("/zlib") or (root.find("/build/generated/") != -1) or (root.find("cmake-build-debug/") != -1) or (root.find("cmake-build-release") != -1) or (root.find("CMakeFiles") != -1):
|
||||
continue
|
||||
for name in files:
|
||||
if (name.endswith(".h") or name.endswith(".m") or name.endswith(".mm") or name.endswith(".hpp") or name.endswith(".cpp") or name.endswith(".java")):
|
||||
localpath = root + '/' + name
|
||||
print localpath
|
||||
os.system("clang-format -i %s -style=File" %(localpath))
|
||||
if any(excluded_dir in root for excluded_dir in excluded_directories):
|
||||
continue
|
||||
for name in files:
|
||||
if name.endswith((".h", ".m", ".mm", ".hpp", ".cpp", ".java")):
|
||||
localpath = os.path.join(root, name)
|
||||
print(localpath)
|
||||
subprocess.run(["clang-format", "-i", localpath, "-style=File"], check=True)
|
||||
|
||||
Reference in New Issue
Block a user