Skip to content

Commit

Permalink
feat: 支持创建设备文件 TencentBlueKing#1575 (TencentBlueKing#1578)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan authored Dec 25, 2023
1 parent 1f89a0b commit 669a966
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class RouteConfiguration(
POST("/create$DEFAULT_MAPPING_URI", nodeOperationsHandler::createNode)
DELETE("/delete$DEFAULT_MAPPING_URI", nodeOperationsHandler::deleteNode)
POST("/mkdir$DEFAULT_MAPPING_URI", nodeOperationsHandler::mkdir)
POST("/mknod$DEFAULT_MAPPING_URI", nodeOperationsHandler::mknod)
PUT("/set-length$DEFAULT_MAPPING_URI", nodeOperationsHandler::setLength)
GET("/stat$DEFAULT_MAPPING_URI", nodeOperationsHandler::getStat)
GET("/info$DEFAULT_MAPPING_URI", nodeOperationsHandler::info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,17 @@ class NodeOperationsHandler(
gid = attrMap[NodeAttribute::gid.name] as? String ?: NOBODY,
mode = attrMap[NodeAttribute::mode.name] as? Int ?: DEFAULT_MODE,
flags = attrMap[NodeAttribute::flags.name] as? Int,
rdev = attrMap[NodeAttribute::rdev.name] as? Int,
type = attrMap[NodeAttribute::type.name] as? Int
)

val attributes = NodeAttribute(
uid = uid ?: preFsAttribute.uid,
gid = gid ?: preFsAttribute.gid,
mode = mode ?: preFsAttribute.mode,
flags = flags ?: preFsAttribute.flags,
rdev = rdev ?: preFsAttribute.rdev,
type = type ?: preFsAttribute.type
)
val fsAttr = MetadataModel(
key = FS_ATTR_KEY,
Expand Down Expand Up @@ -243,6 +247,11 @@ class NodeOperationsHandler(
return ReactiveResponseBuilder.success(node.nodeInfo.toNode())
}

suspend fun mknod(request: ServerRequest): ServerResponse {
val node = createNode(request, false)
return ReactiveResponseBuilder.success(node.nodeInfo.toNode())
}

private suspend fun createNode(request: ServerRequest, folder: Boolean): NodeDetail {
with(NodeRequest(request)) {
val user = ReactiveSecurityUtils.getUser()
Expand All @@ -251,7 +260,9 @@ class NodeOperationsHandler(
uid = NOBODY,
gid = NOBODY,
mode = mode ?: DEFAULT_MODE,
flags = flags
flags = flags,
rdev = rdev,
type = type
)
val fsAttr = MetadataModel(
key = FS_ATTR_KEY,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package com.tencent.bkrepo.fs.server.model

data class NodeAttribute(
// 用户id
val uid: String,
// 组id
val gid: String,
// 文件权限,八进制
val mode: Int? = DEFAULT_MODE,
// windows文件flag,十六进制
val flags: Int? = null,
// 设备文件设备号
val rdev: Int? = null,
// 文件类型
val type: Int? = null
) {
companion object {
const val DEFAULT_MODE = 644
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ open class NodeRequest(
open val category: String = RepositoryCategory.LOCAL.name,
open val mode: Int? = null,
open val flags: Int? = null,
open val rdev: Int? = null,
open val type: Int? = null,
) {
constructor(request: ServerRequest) : this(
projectId = request.pathVariable(PROJECT_ID),
Expand All @@ -57,6 +59,8 @@ open class NodeRequest(
category = request.queryParamOrNull("category") ?: RepositoryCategory.LOCAL.name,
mode = request.queryParamOrNull("mode")?.toIntOrNull(),
flags = request.queryParamOrNull("flags")?.toIntOrNull(),
rdev = request.queryParamOrNull("rdev")?.toIntOrNull(),
type = request.queryParamOrNull("type")?.toIntOrNull()
)

override fun toString(): String {
Expand Down

0 comments on commit 669a966

Please sign in to comment.