Skip to content

Commit c9f330b

Browse files
liqiang-fit2cloudliuruibin
authored andcommitted
refactor: delete .SANDBOX_BANNED_HOSTS file if SANDBOX_PYTHON_BANNED_KEYWORDS is empty/
1 parent 706f387 commit c9f330b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

apps/common/utils/tool_code.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ def __init__(self, sandbox=False):
2828
os.system(f"chown -R {self.user}:root {self.sandbox_path}")
2929
self.banned_keywords = CONFIG.get("SANDBOX_PYTHON_BANNED_KEYWORDS", 'nothing_is_banned').split(',');
3030
try:
31+
banned_hosts_file_path = f'{self.sandbox_path}/.SANDBOX_BANNED_HOSTS'
32+
if os.path.exists(banned_hosts_file_path):
33+
os.remove(banned_hosts_file_path)
3134
banned_hosts = CONFIG.get("SANDBOX_PYTHON_BANNED_HOSTS", '').strip()
3235
if banned_hosts:
3336
hostname = socket.gethostname()
3437
local_ip = socket.gethostbyname(hostname)
3538
banned_hosts = f"{banned_hosts},{hostname},{local_ip}"
36-
banned_hosts_file_path = f'{self.sandbox_path}/.SANDBOX_BANNED_HOSTS'
37-
if os.path.exists(banned_hosts_file_path):
38-
os.remove(banned_hosts_file_path)
3939
with open(banned_hosts_file_path, "w") as f:
4040
f.write(banned_hosts)
4141
os.chmod(banned_hosts_file_path, 0o644)

0 commit comments

Comments
 (0)