Skip to content

Commit

Permalink
fix: 代码优化 #2813
Browse files Browse the repository at this point in the history
  • Loading branch information
zzdjx committed Jan 6, 2025
1 parent 1ca4460 commit 2804cbb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class BlockNodeServiceImpl(
.and(TBlockNode::uploadId.name).isEqualTo(uploadId)
val update = BlockNodeQueryHelper.deleteUpdate()
blockNodeDao.updateFirst(Query(criteria), update)
logger.info("Delete single node block[$projectId/$repoName$nodeFullPath] success. Id: $id, UPLOADID: $uploadId")
logger.info("Delete single node block[$projectId/$repoName$nodeFullPath] success. " +
"Id: $id, UPLOADID: $uploadId")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,31 +417,41 @@ abstract class NodeBaseService(
open fun checkConflictAndQuota(createRequest: NodeCreateRequest, fullPath: String) {
with(createRequest) {
val existNode = nodeDao.findNode(projectId, repoName, fullPath)
if (existNode != null) {
if (!overwrite) {
throw ErrorCodeException(ArtifactMessageCode.NODE_EXISTED, fullPath)
} else if (existNode.folder || this.folder) {
throw ErrorCodeException(ArtifactMessageCode.NODE_CONFLICT, fullPath)
} else if (separate) {
val currentVersion = createRequest.metadata!![UPLOADID_KEY].toString()
val oldNodeId = currentVersion.substringAfter("/")
if (oldNodeId == FAKE_SEPARATE){
return
}
val deleteRes = deleteOldNode(projectId, repoName, fullPath, operator, oldNodeId)
if (deleteRes.deletedNumber == 0L){
logger.warn("Delete block base node[$fullPath] by [$operator] error: node was deleted")
throw ErrorCodeException(ArtifactMessageCode.NODE_NOT_FOUND, fullPath)
}
quotaService.decreaseUsedVolume(projectId, repoName, deleteRes.deletedSize)
} else {
val changeSize = this.size?.minus(existNode.size) ?: -existNode.size
quotaService.checkRepoQuota(projectId, repoName, changeSize)
deleteByFullPathWithoutDecreaseVolume(projectId, repoName, fullPath, operator)
quotaService.decreaseUsedVolume(projectId, repoName, existNode.size)

// 如果节点不存在,进行配额检查后直接返回
if (existNode == null) {
quotaService.checkRepoQuota(projectId, repoName, this.size ?: 0)
return
}

// 如果不允许覆盖,抛出节点已存在异常
if (!overwrite) {
throw ErrorCodeException(ArtifactMessageCode.NODE_EXISTED, fullPath)
}

// 如果存在文件夹冲突,抛出节点冲突异常
if (existNode.folder || this.folder) {
throw ErrorCodeException(ArtifactMessageCode.NODE_CONFLICT, fullPath)
}

// 根据 separate 参数执行不同的逻辑
if (separate) {
val currentVersion = createRequest.metadata!![UPLOADID_KEY].toString()
val oldNodeId = currentVersion.substringAfter("/")
if (oldNodeId == FAKE_SEPARATE) {
return
}
val deleteRes = deleteOldNode(projectId, repoName, fullPath, operator, oldNodeId)
if (deleteRes.deletedNumber == 0L) {
logger.warn("Delete block base node[$fullPath] by [$operator] error: node was deleted")
throw ErrorCodeException(ArtifactMessageCode.NODE_NOT_FOUND, fullPath)
}
quotaService.decreaseUsedVolume(projectId, repoName, deleteRes.deletedSize)
} else {
quotaService.checkRepoQuota(projectId, repoName, this.size ?: 0)
val changeSize = this.size?.minus(existNode.size) ?: -existNode.size
quotaService.checkRepoQuota(projectId, repoName, changeSize)
deleteByFullPathWithoutDecreaseVolume(projectId, repoName, fullPath, operator)
quotaService.decreaseUsedVolume(projectId, repoName, existNode.size)
}
}
}
Expand Down

0 comments on commit 2804cbb

Please sign in to comment.