Skip to content

Commit

Permalink
fix: cos跨存储复制失败,文件误删 TencentBlueKing#2129
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan authored May 10, 2024
1 parent e42c7ab commit 09feb05
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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}]")

0 comments on commit 09feb05

Please sign in to comment.