diff --git a/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/innercos/client/CosClient.kt b/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/innercos/client/CosClient.kt index 23574bcb4f..af5f6fc9c8 100644 --- a/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/innercos/client/CosClient.kt +++ b/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/innercos/client/CosClient.kt @@ -45,6 +45,7 @@ import com.tencent.bkrepo.common.api.stream.EnhanceFileChunkedFutureWrapper import com.tencent.bkrepo.common.artifact.stream.DelegateInputStream import com.tencent.bkrepo.common.storage.credentials.InnerCosCredentials import com.tencent.bkrepo.common.storage.innercos.exception.InnerCosException +import com.tencent.bkrepo.common.storage.innercos.exception.MigrateFailedException import com.tencent.bkrepo.common.storage.innercos.http.CosHttpClient import com.tencent.bkrepo.common.storage.innercos.http.HttpResponseHandler import com.tencent.bkrepo.common.storage.innercos.request.AbortMultipartUploadRequest @@ -305,12 +306,10 @@ class CosClient(val credentials: InnerCosCredentials) { val dstObject = headObject(HeadObjectRequest(key)) // 部分历史文件没有crc64, 此时只校验文件长度 if (crc64 != null && dstObject.crc64ecma != crc64 || dstObject.length != length) { - throw InnerCosException("check crc64 or length failed: " + - "src file[crc64=$crc64, length=$length], " + - "dst file[crc64=${dstObject.crc64ecma}, length=${dstObject.length}]") + throw MigrateFailedException(crc64, length, dstObject.crc64ecma, dstObject.length) } return response - } catch (exception: InnerCosException) { + } catch (exception: MigrateFailedException) { deleteObject(DeleteObjectRequest(key)) throw exception } catch (exception: IOException) { diff --git a/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/innercos/exception/MigrateFailedException.kt b/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/innercos/exception/MigrateFailedException.kt new file mode 100644 index 0000000000..e4ff8e22e9 --- /dev/null +++ b/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/innercos/exception/MigrateFailedException.kt @@ -0,0 +1,37 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.bkrepo.common.storage.innercos.exception + +class MigrateFailedException( + srcCrc64: String?, + srcLength: Long, + dstCrc64: String?, + dstLength: Long?, +) : InnerCosException( + message = "check crc64 or length failed: src file[crc64=$srcCrc64, length=$srcLength]," + + " dst file[crc64=${dstCrc64}, length=${dstLength}]")