fix(plugin): fix null path

This commit is contained in:
qianmoQ 2024-11-29 10:13:03 +08:00
parent 7822cd2f23
commit bc9519b441
3 changed files with 29 additions and 11 deletions

View File

@ -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);

View File

@ -12,10 +12,6 @@
<description>DataCap - File System - Qiniu</description>
<dependencies>
<dependency>
<groupId>io.edurt.datacap</groupId>
<artifactId>datacap-common</artifactId>
</dependency>
<dependency>
<groupId>io.edurt.datacap</groupId>
<artifactId>datacap-fs-spi</artifactId>

View File

@ -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)
}
}