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

Method walk

class/btdockerModel/securityModel.py:190–227  ·  view source on GitHub ↗

遍历目录树

(self, top)

Source from the content-addressed store, hash-verified

188 return []
189
190 def walk(self, top):
191 """遍历目录树"""
192 try:
193 with self._temp_container() as container_id:
194 cmd = f"docker export {container_id} | tar -t"
195 result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
196
197 dir_tree = {}
198 for line in result.stdout.splitlines():
199 line = line.strip().strip('/')
200 if not line or not line.startswith(top.strip('/')):
201 continue
202
203 parts = line.split('/')
204 current_path = ''
205 for i, part in enumerate(parts):
206 parent_path = current_path
207 current_path = os.path.join(current_path, part) if current_path else part
208
209 if current_path not in dir_tree:
210 dir_tree[current_path] = {'dirs': set(), 'files': set()}
211
212 if i < len(parts) - 1:
213 dir_tree[parent_path]['dirs'].add(part)
214 else:
215 dir_tree[parent_path]['files'].add(part)
216
217 for dirpath in sorted(dir_tree.keys()):
218 if not dirpath.startswith(top.strip('/')):
219 continue
220
221 full_path = '/' + dirpath
222 dirs = sorted(dir_tree[dirpath]['dirs'])
223 files = sorted(dir_tree[dirpath]['files'])
224 yield full_path, dirs, files
225
226 except Exception as e:
227 yield top, [], []
228
229 def stat(self, path):
230 """获取文件状态信息"""

Callers 15

_save_optionsMethod · 0.45
_check_path_totalMethod · 0.45
_set_web_path_modMethod · 0.45
__search_filesMethod · 0.45
__replace_filesMethod · 0.45
get_dirMethod · 0.45
get_dir_filesMethod · 0.45
SearchFilesMethod · 0.45
SearchFilesNewMethod · 0.45
get_dirMethod · 0.45
ws_webshell_checkMethod · 0.45
SearchFilesDataMethod · 0.45

Calls 7

_temp_containerMethod · 0.95
setFunction · 0.50
runMethod · 0.45
splitMethod · 0.45
joinMethod · 0.45
addMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected