From e4735c0bae065552db70fc15edcf571f563a9907 Mon Sep 17 00:00:00 2001 From: zzdjx Date: Mon, 13 Jan 2025 12:03:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E4=B8=80=E4=B8=8B?= =?UTF-8?q?=E7=BB=86=E8=8A=82=E9=97=AE=E9=A2=98=20#2813?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bkrepo/generic/service/UploadService.kt | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/service/UploadService.kt b/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/service/UploadService.kt index c111ecece8..e01c575b24 100644 --- a/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/service/UploadService.kt +++ b/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/service/UploadService.kt @@ -256,6 +256,27 @@ class UploadService( fun completeSeparateBlockUpload(userId: String, uploadId: String, artifactInfo: GenericArtifactInfo) { + // 获取并按起始位置排序块信息列表 + val blockInfoList = blockNodeService.listBlocksInUploadId( + artifactInfo.projectId, + artifactInfo.repoName, + artifactInfo.getArtifactFullPath(), + uploadId = uploadId + ) + + blockInfoList.ifEmpty { + logger.warn("No block information found for uploadId: $uploadId") + throw ErrorCodeException(GenericMessageCode.BLOCK_UPDATE_LIST_IS_NULL, artifactInfo) + } + + // 计算所有块的总大小 + val totalSize = blockInfoList.sumOf { it.size } + + // 验证节点大小是否与块总大小一致 + if (getLongHeader(HEADER_FILE_SIZE) != totalSize) { + throw ErrorCodeException(GenericMessageCode.NODE_DATA_ERROR, artifactInfo) + } + // 创建新的基础节点(Base Node) try { blockBaseNodeCreate(userId, artifactInfo, uploadId) @@ -275,25 +296,6 @@ class UploadService( artifactInfo.getArtifactFullPath() ) - // 获取节点信息(不再进行节点存在性检查) - val node = ArtifactContextHolder.getNodeDetail(artifactInfo) - - // 获取并按起始位置排序块信息列表 - val blockInfoList = blockNodeService.listBlocksInUploadId( - node!!.projectId, - node.repoName, - node.fullPath, - uploadId = uploadId - ) - - blockInfoList.ifEmpty { - logger.warn("No block information found for uploadId: $uploadId") - throw ErrorCodeException(GenericMessageCode.BLOCK_UPDATE_LIST_IS_NULL, artifactInfo) - } - - // 计算所有块的总大小 - val totalSize = blockInfoList.sumOf { it.size } - // 更新节点版本信息为null blockNodeService.updateBlockUploadId( artifactInfo.projectId, @@ -302,11 +304,6 @@ class UploadService( uploadId ) - // 验证节点大小是否与块总大小一致 - if (node.size != totalSize) { - throw ErrorCodeException(GenericMessageCode.NODE_DATA_ERROR, artifactInfo) - } - // 上传完成,记录日志 logger.info( "User [$userId] successfully completed block upload [uploadId: $uploadId], " +