Skip to content

Commit

Permalink
feat: Proxy支持删除未同步的文件存储 #1836
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan committed Mar 8, 2024
1 parent 5be36a0 commit cb82a72
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ abstract class AbstractFileStorage<Credentials : StorageCredentials, Client> : F
copy(path, name, fromClient, toClient)
}

override fun move(
fromPath: String,
fromName: String,
toPath: String,
toName: String,
fromCredentials: StorageCredentials,
toCredentials: StorageCredentials
) {
val fromClient = getClient(fromCredentials)
val toClient = getClient(toCredentials)
move(fromPath, fromName, toPath, toName, fromClient, toClient)
}

private fun getClient(storageCredentials: StorageCredentials): Client {
return if (storageCredentials == storageProperties.defaultStorageCredentials()) {
defaultClient
Expand All @@ -177,6 +190,17 @@ abstract class AbstractFileStorage<Credentials : StorageCredentials, Client> : F
throw UnsupportedOperationException("Copy operation unsupported")
}

open fun move(
fromPath: String,
fromName: String,
toPath: String,
toName: String,
fromClient: Client,
toClient: Client
) {
throw UnsupportedOperationException("Move operation unsupported")
}

companion object {
private val logger = LoggerFactory.getLogger(AbstractFileStorage::class.java)
private const val MAX_CACHE_CLIENT = 10L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ interface FileStorage {
*/
fun copy(path: String, name: String, fromCredentials: StorageCredentials, toCredentials: StorageCredentials)

/**
* 在不同存储实例之间移动文件
* @param fromPath 文件源路径
* @param fromName 文件源名称
* @param toPath 文件目标路径
* @param toName 文件目标名称
* @param fromCredentials 源存储凭证
* @param toCredentials 目的存储凭证
*/
fun move(
fromPath: String,
fromName: String,
toPath: String,
toName: String,
fromCredentials: StorageCredentials,
toCredentials: StorageCredentials
)

/**
* 获取存储的临时目录,默认实现返回`java.io.tmpdir`目录
* @param storageCredentials 存储凭证
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import java.nio.file.Paths
/**
* 本地文件存储客户端
*/
class FileSystemClient(private val root: String) {
class FileSystemClient(val root: String) {

constructor(path: Path) : this(path.toString())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ import com.tencent.bkrepo.common.storage.credentials.FileSystemCredentials
import com.tencent.bkrepo.common.storage.credentials.StorageCredentials
import java.io.File
import java.io.InputStream
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption

/**
* 文件系统存储
Expand Down Expand Up @@ -76,4 +78,17 @@ open class FileSystemStorage : AbstractEncryptorFileStorage<FileSystemCredential
require(storageCredentials is FileSystemCredentials)
return Paths.get(storageCredentials.path, TEMP).toString()
}

override fun move(
fromPath: String,
fromName: String,
toPath: String,
toName: String,
fromClient: FileSystemClient,
toClient: FileSystemClient
) {
val fromFullPath = Paths.get(fromClient.root, fromPath, fromName)
val toFullPath = Paths.get(toClient.root, toPath, toName)
Files.move(fromFullPath, toFullPath, StandardCopyOption.REPLACE_EXISTING)
}
}

0 comments on commit cb82a72

Please sign in to comment.