获取文件状态信息
(self, path)
| 227 | yield top, [], [] |
| 228 | |
| 229 | def stat(self, path): |
| 230 | """获取文件状态信息""" |
| 231 | try: |
| 232 | with self._temp_container() as container_id: |
| 233 | cmd = f"docker export {container_id} | tar -tvf - {path.lstrip('/')}" |
| 234 | result = subprocess.run(cmd, shell=True, capture_output=True, text=True) |
| 235 | |
| 236 | if result.returncode != 0: |
| 237 | raise Exception("文件不存在") |
| 238 | |
| 239 | info = result.stdout.strip().split(None, 5)[0:5] |
| 240 | mode, uid, gid, size = info[0], info[2], info[3], info[4] |
| 241 | |
| 242 | class StatResult: |
| 243 | def __init__(self, mode, size, uid, gid): |
| 244 | self.st_mode = int(mode, 8) |
| 245 | self.st_size = int(size) |
| 246 | self.st_uid = int(uid) |
| 247 | self.st_gid = int(gid) |
| 248 | |
| 249 | return StatResult(mode, size, uid, gid) |
| 250 | |
| 251 | except Exception as e: |
| 252 | raise |
| 253 | |
| 254 | def open(self, path, mode="rb"): |
| 255 | """打开文件""" |
no test coverage detected