MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / open

Method open

class/btdockerModel/securityModel.py:254–278  ·  view source on GitHub ↗

打开文件

(self, path, mode="rb")

Source from the content-addressed store, hash-verified

252 raise
253
254 def open(self, path, mode="rb"):
255 """打开文件"""
256 try:
257 with self._temp_container() as container_id:
258 cmd = f"docker export {container_id} | tar -xOf - {path.lstrip('/')}"
259 result = subprocess.run(cmd, shell=True, capture_output=True)
260
261 if result.returncode != 0:
262 raise Exception("无法读取文件")
263
264 class FileWrapper:
265 def __init__(self, data):
266 self.data = data
267 self.position = 0
268
269 def read(self):
270 return self.data
271
272 def close(self):
273 pass
274
275 return FileWrapper(result.stdout)
276
277 except Exception as e:
278 raise
279
280 def cleanup(self):
281 """清理所有活动的临时容器"""

Callers 6

scan_sensitiveMethod · 0.45
bashrcMethod · 0.45
crontabMethod · 0.45
serviceMethod · 0.45
tcpwrapperMethod · 0.45
sudoersMethod · 0.45

Calls 3

_temp_containerMethod · 0.95
FileWrapperClass · 0.85
runMethod · 0.45

Tested by

no test coverage detected