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

Method clean_chunks

core/storage.py:494–514  ·  view source on GitHub ↗

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

(self, upload_id: str, save_path: str)

Source from the content-addressed store, hash-verified

492 return save_path, file_sha256.hexdigest()
493
494 async def clean_chunks(self, upload_id: str, save_path: str):
495 """
496 清理 S3 上的临时分片文件
497 :param upload_id: 上传会话ID
498 :param save_path: 文件保存路径
499 """
500 chunk_dir = str(Path(save_path).parent / "chunks" / upload_id)
501 async with self._client() as s3:
502 try:
503 # 列出并删除所有分片对象
504 paginator = s3.get_paginator('list_objects_v2')
505 async for page in paginator.paginate(Bucket=self.bucket_name, Prefix=chunk_dir):
506 objects = page.get('Contents', [])
507 if objects:
508 delete_objects = [{'Key': obj['Key']} for obj in objects]
509 await s3.delete_objects(
510 Bucket=self.bucket_name,
511 Delete={'Objects': delete_objects}
512 )
513 except Exception as e:
514 logger.info(f"清理 S3 分片数据时出错: {e}")
515
516 async def generate_presigned_upload_url(self, save_path: str, expires_in: int = 900) -> Optional[str]:
517 """

Callers 3

clean_incomplete_uploadsFunction · 0.45
cancel_uploadFunction · 0.45
complete_uploadFunction · 0.45

Calls 1

_clientMethod · 0.95

Tested by

no test coverage detected