MCPcopy Index your code
hub / github.com/vastsa/FileCodeBox / delete_file

Method delete_file

core/storage.py:1119–1139  ·  view source on GitHub ↗

删除WebDAV文件及空目录

(self, file_code: FileCodes)

Source from the content-addressed store, hash-verified

1117 status_code=503, detail=f"WebDAV连接异常: {str(e)}")
1118
1119 async def delete_file(self, file_code: FileCodes):
1120 """删除WebDAV文件及空目录"""
1121 file_path = await file_code.get_file_path()
1122 url = self._build_url(file_path)
1123 try:
1124 async with aiohttp.ClientSession(auth=self.auth) as session:
1125 # 删除文件
1126 async with session.delete(url) as resp:
1127 if resp.status not in (200, 204, 404):
1128 content = await resp.text()
1129 raise HTTPException(
1130 status_code=resp.status,
1131 detail=f"WebDAV删除失败: {content[:200]}",
1132 )
1133
1134 # 使用同一个 session 删除空目录
1135 await self._delete_empty_dirs(file_path, session)
1136
1137 except aiohttp.ClientError as e:
1138 raise HTTPException(
1139 status_code=503, detail=f"WebDAV连接异常: {str(e)}")
1140
1141 async def get_file_url(self, file_code: FileCodes):
1142 return await get_file_url(file_code.code)

Callers

nothing calls this directly

Calls 4

_build_urlMethod · 0.95
_delete_empty_dirsMethod · 0.95
get_file_pathMethod · 0.80
deleteMethod · 0.80

Tested by

no test coverage detected