diff --git a/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/core/AbstractFileStorage.kt b/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/core/AbstractFileStorage.kt index bdf25efc24..c2333571d0 100644 --- a/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/core/AbstractFileStorage.kt +++ b/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/core/AbstractFileStorage.kt @@ -159,6 +159,19 @@ abstract class AbstractFileStorage : 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 @@ -177,6 +190,17 @@ abstract class AbstractFileStorage : 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 diff --git a/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/core/FileStorage.kt b/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/core/FileStorage.kt index 747a672f17..f9f0ebb1f3 100644 --- a/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/core/FileStorage.kt +++ b/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/core/FileStorage.kt @@ -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 存储凭证 diff --git a/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/filesystem/FileSystemClient.kt b/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/filesystem/FileSystemClient.kt index 8b8769871e..07d43d0bd0 100644 --- a/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/filesystem/FileSystemClient.kt +++ b/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/filesystem/FileSystemClient.kt @@ -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()) diff --git a/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/filesystem/FileSystemStorage.kt b/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/filesystem/FileSystemStorage.kt index b70dafced6..6ce3221b28 100644 --- a/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/filesystem/FileSystemStorage.kt +++ b/src/backend/common/common-storage/storage-service/src/main/kotlin/com/tencent/bkrepo/common/storage/filesystem/FileSystemStorage.kt @@ -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 /** * 文件系统存储 @@ -76,4 +78,17 @@ open class FileSystemStorage : AbstractEncryptorFileStorage