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

Method clean_chunks

core/storage.py:1284–1316  ·  view source on GitHub ↗

清理 WebDAV 上的临时分片文件 :param upload_id: 上传会话ID :param save_path: 文件保存路径

(self, upload_id: str, save_path: str)

Source from the content-addressed store, hash-verified

1282 return save_path, file_sha256.hexdigest()
1283
1284 async def clean_chunks(self, upload_id: str, save_path: str):
1285 """
1286 清理 WebDAV 上的临时分片文件
1287 :param upload_id: 上传会话ID
1288 :param save_path: 文件保存路径
1289 """
1290 chunk_dir = str(Path(save_path).parent / "chunks" / upload_id)
1291 chunk_dir_url = self._build_url(chunk_dir)
1292 async with aiohttp.ClientSession(auth=self.auth) as session:
1293 try:
1294 # 检查分片目录是否存在
1295 async with session.request("PROPFIND", chunk_dir_url, headers={"Depth": "1"}) as resp:
1296 if resp.status == 207: # 207 表示 Multi-Status
1297 # 获取目录下的所有分片文件
1298 xml_data = await resp.text()
1299 file_paths = re.findall(
1300 r'<D:href>(.*?)</D:href>', xml_data)
1301 for file_path in file_paths:
1302 if file_path.endswith(".part"):
1303 # 删除分片文件
1304 file_url = self._build_url(file_path)
1305 async with session.delete(file_url) as delete_resp:
1306 if delete_resp.status not in (200, 204, 404):
1307 logger.info(f"删除分片文件失败: {file_path}")
1308
1309 # 删除分片目录
1310 async with session.delete(chunk_dir_url) as delete_resp:
1311 if delete_resp.status not in (200, 204, 404):
1312 logger.info(f"删除分片目录失败: {chunk_dir_url}")
1313 else:
1314 logger.info(f"分片目录不存在: {chunk_dir_url}")
1315 except Exception as e:
1316 logger.info(f"清理 WebDAV 分片时出错: {e}")
1317
1318 async def file_exists(self, save_path: str) -> bool:
1319 """

Callers

nothing calls this directly

Calls 2

_build_urlMethod · 0.95
deleteMethod · 0.80

Tested by

no test coverage detected