MCPcopy
hub / github.com/TaskingAI/TaskingAI / delete_file

Method delete_file

backend/tkhelper/database/boto3/client.py:381–416  ·  view source on GitHub ↗

Delete file from minio :param bucket_name: the name of the bucket :param purpose: the purpose of the file :param file_id: the id of the file, e.g. txt_x123456 :param tenant_id: the id of the tenant. Error will be raised if the tenant_id is not valid :

(
        self,
        bucket_name: str,
        purpose: str,
        file_id: str,
        tenant_id: str,
    )

Source from the content-addressed store, hash-verified

379 return f"{self._host_url}/{path}/{file}"
380
381 async def delete_file(
382 self,
383 bucket_name: str,
384 purpose: str,
385 file_id: str,
386 tenant_id: str,
387 ) -> bool:
388 """
389 Delete file from minio
390 :param bucket_name: the name of the bucket
391 :param purpose: the purpose of the file
392 :param file_id: the id of the file, e.g. txt_x123456
393 :param tenant_id: the id of the tenant. Error will be raised if the tenant_id is not valid
394 :return: True if the file is deleted successfully, False otherwise
395 """
396
397 ext, _id = _validate_file_id(file_id)
398 key = _object_key(purpose, _id, ext, tenant_id)
399 if not await self.check_file_exists(bucket_name, purpose, file_id, tenant_id):
400 raise_http_error(ErrorCode.OBJECT_NOT_FOUND, f"File {file_id} not found")
401 try:
402 if self._is_s3:
403 async with self._session.client(
404 service_name=self._service_name, endpoint_url=self._endpoint_url
405 ) as client:
406 await client.delete_object(
407 Bucket=bucket_name,
408 Key=key,
409 )
410 else:
411 path = key.removesuffix(f".{ext}")
412 await self.delete_volume_file(path=path)
413 return True
414 except Exception as e:
415 logger.error(f"delete_file: failed to delete file {file_id}, e={e}")
416 return False
417
418 def get_volume_file_abs_path(self, path):
419 """

Callers 1

load_content_to_splitFunction · 0.80

Calls 5

check_file_existsMethod · 0.95
delete_volume_fileMethod · 0.95
raise_http_errorFunction · 0.90
_validate_file_idFunction · 0.85
_object_keyFunction · 0.85

Tested by

no test coverage detected