Skip to content

Commit

Permalink
fix: 修复一些小问题 #2927
Browse files Browse the repository at this point in the history
  • Loading branch information
zzdjx committed Jan 15, 2025
1 parent 48934aa commit 08c885e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ import com.tencent.bkrepo.generic.constant.BKREPO_META
import com.tencent.bkrepo.generic.constant.BKREPO_META_PREFIX
import com.tencent.bkrepo.generic.constant.CHUNKED_UPLOAD
import com.tencent.bkrepo.generic.constant.GenericMessageCode
import com.tencent.bkrepo.generic.constant.HEADER_BLOCK_APPEND
import com.tencent.bkrepo.generic.constant.HEADER_EXPIRES
import com.tencent.bkrepo.generic.constant.HEADER_MD5
import com.tencent.bkrepo.generic.constant.HEADER_OFFSET
import com.tencent.bkrepo.generic.constant.HEADER_OVERWRITE
import com.tencent.bkrepo.generic.constant.HEADER_SEQUENCE
import com.tencent.bkrepo.generic.constant.HEADER_SHA256
import com.tencent.bkrepo.generic.constant.HEADER_SIZE
import com.tencent.bkrepo.generic.constant.HEADER_UPLOAD_ID
import com.tencent.bkrepo.generic.constant.HEADER_UPLOAD_TYPE
import com.tencent.bkrepo.generic.constant.HEADER_OFFSET
import com.tencent.bkrepo.generic.constant.HEADER_SIZE
import com.tencent.bkrepo.generic.constant.HEADER_OVERWRITE
import com.tencent.bkrepo.generic.constant.HEADER_BLOCK_APPEND
import com.tencent.bkrepo.generic.constant.HEADER_EXPIRES
import com.tencent.bkrepo.generic.constant.SEPARATE_UPLOAD
import com.tencent.bkrepo.generic.pojo.ChunkedResponseProperty
import com.tencent.bkrepo.generic.pojo.SeparateBlockInfo
Expand Down Expand Up @@ -133,9 +133,7 @@ import org.springframework.util.unit.DataSize
import java.net.URLDecoder
import java.time.Duration
import java.time.LocalDateTime
import java.util.Base64
import java.util.Locale
import java.util.UUID
import java.util.*
import java.util.concurrent.TimeUnit
import javax.servlet.http.HttpServletRequest
import kotlin.reflect.full.memberProperties
Expand Down Expand Up @@ -185,7 +183,7 @@ class GenericLocalRepository(
val uploadType = HeaderUtils.getHeader(HEADER_UPLOAD_TYPE)

when {
isSeparateUpload(uploadType) -> {
isSeparateUpload(uploadId, uploadType) -> {
onSeparateUpload(context, uploadId)
}
isBlockUpload(uploadId, sequence) -> {
Expand Down Expand Up @@ -251,8 +249,8 @@ class GenericLocalRepository(
}
}

private fun isSeparateUpload(uploadType: String?): Boolean {
return !uploadType.isNullOrEmpty() && uploadType == SEPARATE_UPLOAD
private fun isSeparateUpload(uploadId: String?, uploadType: String?): Boolean {
return !uploadType.isNullOrEmpty() && uploadType == SEPARATE_UPLOAD && !uploadId.isNullOrEmpty()
}

override fun onUploadSuccess(context: ArtifactUploadContext) {
Expand Down Expand Up @@ -317,7 +315,7 @@ class GenericLocalRepository(
val sequence = HeaderUtils.getHeader(HEADER_SEQUENCE)?.toInt()
val uploadType = HeaderUtils.getHeader(HEADER_UPLOAD_TYPE)
if (!overwrite && !isBlockUpload(uploadId, sequence)
&& !isChunkedUpload(uploadType) && !isSeparateUpload(uploadType)) {
&& !isChunkedUpload(uploadType) && !isSeparateUpload(uploadId, uploadType)) {
with(context.artifactInfo) {
nodeService.getNodeDetail(this)?.let {
throw ErrorCodeException(ArtifactMessageCode.NODE_EXISTED, getArtifactName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.tencent.bkrepo.common.api.constant.StringPool
import com.tencent.bkrepo.common.api.exception.BadRequestException
import com.tencent.bkrepo.common.api.exception.ErrorCodeException
import com.tencent.bkrepo.common.api.message.CommonMessageCode
import com.tencent.bkrepo.common.api.util.Preconditions
import com.tencent.bkrepo.common.artifact.api.ArtifactFile
import com.tencent.bkrepo.common.artifact.message.ArtifactMessageCode
import com.tencent.bkrepo.common.artifact.pojo.RepositoryCategory
Expand Down Expand Up @@ -98,9 +99,9 @@ class UploadService(

fun startBlockUpload(userId: String, artifactInfo: GenericArtifactInfo): UploadTransactionInfo {
with(artifactInfo) {

val expires = getLongHeader(HEADER_EXPIRES)
val overwrite = getBooleanHeader(HEADER_OVERWRITE)

Preconditions.checkArgument(expires >= 0, "expires")
// 判断文件是否存在
if (!overwrite && nodeService.checkExist(this)) {
logger.warn(
Expand Down Expand Up @@ -132,8 +133,6 @@ class UploadService(

val node = nodeService.getNodeDetail(this)

val expires = getLongHeader(HEADER_EXPIRES).takeIf { it > 0 } ?: TRANSACTION_EXPIRES

val oldNodeId = node?.nodeInfo?.id ?: FAKE_SEPARATE
// 如果不允许覆盖且节点已经存在,抛出异常
if (node != null && !overwrite) {
Expand All @@ -146,7 +145,7 @@ class UploadService(
// 创建上传事务信息,设置过期时间
val uploadTransaction = UploadTransactionInfo(
uploadId = uploadId,
expireSeconds = expires
expireSeconds = TRANSACTION_EXPIRES
)
// 记录上传启动的日志
logger.info(
Expand Down Expand Up @@ -256,11 +255,15 @@ class UploadService(

fun completeSeparateBlockUpload(userId: String, uploadId: String, artifactInfo: GenericArtifactInfo) {

val projectId = artifactInfo.projectId
val repoName = artifactInfo.repoName
val artifactFullPath = artifactInfo.getArtifactFullPath()

// 获取并按起始位置排序块信息列表
val blockInfoList = blockNodeService.listBlocksInUploadId(
artifactInfo.projectId,
artifactInfo.repoName,
artifactInfo.getArtifactFullPath(),
projectId,
repoName,
artifactFullPath,
uploadId = uploadId
)

Expand Down Expand Up @@ -291,25 +294,24 @@ class UploadService(

// 删除旧Block
blockNodeService.deleteBlocks(
artifactInfo.projectId,
artifactInfo.repoName,
artifactInfo.getArtifactFullPath()
projectId,
repoName,
artifactFullPath
)

// 更新节点版本信息为null
blockNodeService.updateBlockUploadId(
artifactInfo.projectId,
artifactInfo.repoName,
artifactInfo.getArtifactFullPath(),
projectId,
repoName,
artifactFullPath,
uploadId
)

// 上传完成,记录日志
logger.info(
"User [$userId] successfully completed block upload [uploadId: $uploadId], " +
"file path [${artifactInfo.getArtifactFullPath()}]."
"file path [${artifactFullPath}]."
)

}

fun listBlock(userId: String, uploadId: String, artifactInfo: GenericArtifactInfo): List<BlockInfo> {
Expand Down

0 comments on commit 08c885e

Please sign in to comment.