mirror of
https://gitee.com/devlive-community/datacap.git
synced 2024-11-29 18:48:23 +08:00
[Fs] [Amazon S3] Support delete
This commit is contained in:
parent
24089f2143
commit
bca099f476
@ -61,4 +61,26 @@ class AmazonS3Fs : Fs
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
override fun delete(request: FsRequest?): FsResponse
|
||||
{
|
||||
requireNotNull(request) { "request must not be null" }
|
||||
|
||||
try
|
||||
{
|
||||
val status = AmazonS3Utils.delete(request)
|
||||
log.info("{} delete [ {} ] successfully", this.name(), request.fileName)
|
||||
return FsResponse.builder()
|
||||
.successful(status)
|
||||
.build()
|
||||
}
|
||||
catch (e: java.lang.Exception)
|
||||
{
|
||||
log.error("{} delete error", this.name(), e)
|
||||
return FsResponse.builder()
|
||||
.successful(false)
|
||||
.message(e.message)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,5 +122,25 @@ class AmazonS3Utils
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun delete(request: FsRequest): Boolean
|
||||
{
|
||||
val client = getClient(request)
|
||||
|
||||
try
|
||||
{
|
||||
client.deleteObject(request.bucket, request.fileName)
|
||||
return true
|
||||
}
|
||||
catch (e: Exception)
|
||||
{
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.shutdown()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,4 +73,14 @@ class AmazonS3FsTest
|
||||
log.error("Reader error", e)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun delete()
|
||||
{
|
||||
val plugins: Set<Fs?>? = injector?.getInstance(Key.get(object : TypeLiteral<Set<Fs?>?>()
|
||||
{}))
|
||||
val plugin: Fs? = plugins?.first { v -> v?.name().equals(name) }
|
||||
val response = plugin !!.delete(request)
|
||||
assertTrue(response.isSuccessful)
|
||||
}
|
||||
}
|
||||
|
@ -34,4 +34,10 @@ class AmazonS3UtilsTest
|
||||
{
|
||||
assertNotNull(AmazonS3Utils.reader(request))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun delete()
|
||||
{
|
||||
assertTrue(AmazonS3Utils.delete(request))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user