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

Method stat

class/btdockerModel/securityModel.py:229–252  ·  view source on GitHub ↗

获取文件状态信息

(self, path)

Source from the content-addressed store, hash-verified

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 """打开文件"""

Callers 15

initialize_backup_folderFunction · 0.80
sess_expireMethod · 0.80
detect_by_pathMethod · 0.80
get_path_permissionMethod · 0.80
set_path_permissionMethod · 0.80
logMethod · 0.80
pass_dir_for_userFunction · 0.80
get_remote_file_sizeMethod · 0.80
change_well_known_modMethod · 0.80
check_special_fileMethod · 0.80
executeMethod · 0.80
get_master_sql_listMethod · 0.80

Calls 4

_temp_containerMethod · 0.95
StatResultClass · 0.85
runMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected