mirror of
https://gitee.com/devlive-community/datacap.git
synced 2024-12-05 05:27:52 +08:00
fix(plugin): fix null path
This commit is contained in:
parent
7822cd2f23
commit
bc9519b441
@ -1,9 +1,8 @@
|
|||||||
package io.edurt.datacap.fs;
|
package io.edurt.datacap.fs;
|
||||||
|
|
||||||
import io.edurt.datacap.common.utils.UrlUtils;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.io.File;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LocalFsService
|
public class LocalFsService
|
||||||
@ -13,7 +12,12 @@ public class LocalFsService
|
|||||||
public FsResponse writer(FsRequest request)
|
public FsResponse writer(FsRequest request)
|
||||||
{
|
{
|
||||||
log.info("LocalFs writer origin path [ {} ]", request.getLocalPath());
|
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()
|
FsResponse response = FsResponse.builder()
|
||||||
.origin(request.getLocalPath())
|
.origin(request.getLocalPath())
|
||||||
.remote(targetPath)
|
.remote(targetPath)
|
||||||
@ -40,7 +44,11 @@ public class LocalFsService
|
|||||||
@Override
|
@Override
|
||||||
public FsResponse reader(FsRequest request)
|
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);
|
log.info("LocalFs reader origin path [ {} ]", targetPath);
|
||||||
FsResponse response = FsResponse.builder()
|
FsResponse response = FsResponse.builder()
|
||||||
.remote(targetPath)
|
.remote(targetPath)
|
||||||
@ -61,7 +69,11 @@ public class LocalFsService
|
|||||||
@Override
|
@Override
|
||||||
public FsResponse delete(FsRequest request)
|
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);
|
log.info("LocalFs delete origin path [ {} ]", targetPath);
|
||||||
try {
|
try {
|
||||||
boolean status = IOUtils.delete(targetPath);
|
boolean status = IOUtils.delete(targetPath);
|
||||||
|
@ -12,10 +12,6 @@
|
|||||||
<description>DataCap - File System - Qiniu</description>
|
<description>DataCap - File System - Qiniu</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>io.edurt.datacap</groupId>
|
|
||||||
<artifactId>datacap-common</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.edurt.datacap</groupId>
|
<groupId>io.edurt.datacap</groupId>
|
||||||
<artifactId>datacap-fs-spi</artifactId>
|
<artifactId>datacap-fs-spi</artifactId>
|
||||||
|
@ -13,6 +13,7 @@ import org.junit.Test
|
|||||||
import org.junit.runners.MethodSorters
|
import org.junit.runners.MethodSorters
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
|
import java.nio.file.Path
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
@ -43,13 +44,21 @@ abstract class BaseServiceTest(
|
|||||||
System.getProperty("user.dir"),
|
System.getProperty("user.dir"),
|
||||||
"src", "test", "kotlin", "io", "edurt", "datacap", "test", "BaseServiceTest.kt"
|
"src", "test", "kotlin", "io", "edurt", "datacap", "test", "BaseServiceTest.kt"
|
||||||
).toString()
|
).toString()
|
||||||
|
|
||||||
log.info("local path [ {} ]", localPath)
|
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()
|
request = FsRequest.builder()
|
||||||
.access(System.getProperty("$pluginPrefix.access"))
|
.access(System.getProperty("$pluginPrefix.access"))
|
||||||
.secret(System.getProperty("$pluginPrefix.secret"))
|
.secret(System.getProperty("$pluginPrefix.secret"))
|
||||||
.bucket(System.getProperty("$pluginPrefix.bucket"))
|
.bucket(System.getProperty("$pluginPrefix.bucket"))
|
||||||
.endpoint(System.getProperty("$pluginPrefix.endpoint"))
|
.endpoint(endpoint)
|
||||||
.stream(FileInputStream(localPath))
|
.stream(FileInputStream(localPath))
|
||||||
.fileName(fileName)
|
.fileName(fileName)
|
||||||
.build()
|
.build()
|
||||||
@ -76,6 +85,7 @@ abstract class BaseServiceTest(
|
|||||||
plugin.ifPresent {
|
plugin.ifPresent {
|
||||||
val service = it.getService(FsService::class.java)
|
val service = it.getService(FsService::class.java)
|
||||||
val response = service.writer(request)
|
val response = service.writer(request)
|
||||||
|
log.info("Writer response [ {} ]", response)
|
||||||
assertTrue(response.isSuccessful)
|
assertTrue(response.isSuccessful)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user