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

Method listdir

class/btdockerModel/securityModel.py:164–188  ·  view source on GitHub ↗

列出指定路径下的所有文件和目录

(self, path)

Source from the content-addressed store, hash-verified

162 pass
163
164 def listdir(self, path):
165 """列出指定路径下的所有文件和目录"""
166 try:
167 with self._temp_container() as container_id:
168 cmd = f"docker export {container_id} | tar -t"
169 result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
170
171 files = set()
172 for line in result.stdout.splitlines():
173 line = line.strip().strip('/')
174 if not line:
175 continue
176
177 rel_path = os.path.relpath(line, path.strip('/'))
178 if rel_path.startswith('..'):
179 continue
180
181 parts = rel_path.split('/')
182 if len(parts) == 1:
183 files.add(parts[0])
184
185 return list(files)
186
187 except Exception as e:
188 return []
189
190 def walk(self, top):
191 """遍历目录树"""

Callers 15

do_onceMethod · 0.80
save_installed_msgMethod · 0.80
GetFilesCountFunction · 0.80
ClearMailFunction · 0.80
ClearSessionFunction · 0.80
ClearOtherFunction · 0.80
sync_tencent_sslFunction · 0.80
update_to6Function · 0.80
GetFilesCountFunction · 0.80
ClearMailFunction · 0.80
ClearSessionFunction · 0.80
ClearOtherFunction · 0.80

Calls 5

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

Tested by 2

test_get_web_confMethod · 0.64
test_backupMethod · 0.64