[Fs] [Amazon S3] Support delete

This commit is contained in:
qianmoQ 2024-08-25 19:50:11 +08:00
parent 24089f2143
commit bca099f476
4 changed files with 58 additions and 0 deletions

View File

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

View File

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

View File

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

View File

@ -34,4 +34,10 @@ class AmazonS3UtilsTest
{
assertNotNull(AmazonS3Utils.reader(request))
}
@Test
fun delete()
{
assertTrue(AmazonS3Utils.delete(request))
}
}