列出指定路径下的所有文件和目录
(self, path)
| 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 | """遍历目录树""" |