From bc9519b44171c227373d834d910eebde7fa53df1 Mon Sep 17 00:00:00 2001 From: qianmoQ Date: Fri, 29 Nov 2024 10:13:03 +0800 Subject: [PATCH] fix(plugin): fix null path --- .../io/edurt/datacap/fs/LocalFsService.java | 22 ++++++++++++++----- fs/datacap-fs-qiniu/pom.xml | 4 ---- .../io/edurt/datacap/test/BaseServiceTest.kt | 14 ++++++++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/fs/datacap-fs-local/src/main/java/io/edurt/datacap/fs/LocalFsService.java b/fs/datacap-fs-local/src/main/java/io/edurt/datacap/fs/LocalFsService.java index d27da4f1..ab5837d5 100644 --- a/fs/datacap-fs-local/src/main/java/io/edurt/datacap/fs/LocalFsService.java +++ b/fs/datacap-fs-local/src/main/java/io/edurt/datacap/fs/LocalFsService.java @@ -1,9 +1,8 @@ package io.edurt.datacap.fs; -import io.edurt.datacap.common.utils.UrlUtils; import lombok.extern.slf4j.Slf4j; -import java.io.File; +import java.nio.file.Paths; @Slf4j public class LocalFsService @@ -13,7 +12,12 @@ public class LocalFsService public FsResponse writer(FsRequest request) { log.info("LocalFs writer origin path [ {} ]", request.getLocalPath()); - String targetPath = UrlUtils.fixUrl(String.join(File.separator, request.getEndpoint(), request.getBucket(), request.getFileName())); + String targetPath = Paths.get( + request.getEndpoint() != null ? request.getEndpoint() : "", + request.getBucket() != null ? request.getBucket() : "", + request.getFileName() + ).toString(); + FsResponse response = FsResponse.builder() .origin(request.getLocalPath()) .remote(targetPath) @@ -40,7 +44,11 @@ public class LocalFsService @Override public FsResponse reader(FsRequest request) { - String targetPath = String.join(File.separator, request.getEndpoint(), request.getBucket(), request.getFileName()); + String targetPath = Paths.get( + request.getEndpoint() != null ? request.getEndpoint() : "", + request.getBucket() != null ? request.getBucket() : "", + request.getFileName() + ).toString(); log.info("LocalFs reader origin path [ {} ]", targetPath); FsResponse response = FsResponse.builder() .remote(targetPath) @@ -61,7 +69,11 @@ public class LocalFsService @Override public FsResponse delete(FsRequest request) { - String targetPath = String.join(File.separator, request.getEndpoint(), request.getBucket(), request.getFileName()); + String targetPath = Paths.get( + request.getEndpoint() != null ? request.getEndpoint() : "", + request.getBucket() != null ? request.getBucket() : "", + request.getFileName() + ).toString(); log.info("LocalFs delete origin path [ {} ]", targetPath); try { boolean status = IOUtils.delete(targetPath); diff --git a/fs/datacap-fs-qiniu/pom.xml b/fs/datacap-fs-qiniu/pom.xml index be2a761d..23587d34 100644 --- a/fs/datacap-fs-qiniu/pom.xml +++ b/fs/datacap-fs-qiniu/pom.xml @@ -12,10 +12,6 @@ DataCap - File System - Qiniu - - io.edurt.datacap - datacap-common - io.edurt.datacap datacap-fs-spi diff --git a/test/datacap-test-fs/src/test/kotlin/io/edurt/datacap/test/BaseServiceTest.kt b/test/datacap-test-fs/src/test/kotlin/io/edurt/datacap/test/BaseServiceTest.kt index 87763466..c7409d31 100644 --- a/test/datacap-test-fs/src/test/kotlin/io/edurt/datacap/test/BaseServiceTest.kt +++ b/test/datacap-test-fs/src/test/kotlin/io/edurt/datacap/test/BaseServiceTest.kt @@ -13,6 +13,7 @@ import org.junit.Test import org.junit.runners.MethodSorters import org.slf4j.LoggerFactory import java.io.FileInputStream +import java.nio.file.Path import java.nio.file.Paths import java.util.* import kotlin.test.assertTrue @@ -43,13 +44,21 @@ abstract class BaseServiceTest( System.getProperty("user.dir"), "src", "test", "kotlin", "io", "edurt", "datacap", "test", "BaseServiceTest.kt" ).toString() - log.info("local path [ {} ]", localPath) + + var endpoint = System.getProperty("$pluginPrefix.endpoint") + if (endpoint == null) + { + val tempDir: Path = Paths.get(System.getProperty("user.dir"), "data") + endpoint = tempDir.toString() + } + log.info("endpoint [ {} ]", endpoint) + request = FsRequest.builder() .access(System.getProperty("$pluginPrefix.access")) .secret(System.getProperty("$pluginPrefix.secret")) .bucket(System.getProperty("$pluginPrefix.bucket")) - .endpoint(System.getProperty("$pluginPrefix.endpoint")) + .endpoint(endpoint) .stream(FileInputStream(localPath)) .fileName(fileName) .build() @@ -76,6 +85,7 @@ abstract class BaseServiceTest( plugin.ifPresent { val service = it.getService(FsService::class.java) val response = service.writer(request) + log.info("Writer response [ {} ]", response) assertTrue(response.isSuccessful) } }