From 9e58b7abb3354a066b2fa4d424b3e077b4b2d7f7 Mon Sep 17 00:00:00 2001 From: Elizabeth Paige Harper Date: Wed, 29 May 2024 11:54:48 -0400 Subject: [PATCH] handle special case where entire root path is just a slash --- lib/build.gradle.kts | 2 +- .../lib/compute/platform/intern/s3/S3.kt | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 420cbcb..9e9a8a5 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "org.veupathdb.lib" -version = "1.7.3" +version = "1.7.4" dependencies { diff --git a/lib/src/main/kotlin/org/veupathdb/lib/compute/platform/intern/s3/S3.kt b/lib/src/main/kotlin/org/veupathdb/lib/compute/platform/intern/s3/S3.kt index 1fdf36f..2b492a6 100644 --- a/lib/src/main/kotlin/org/veupathdb/lib/compute/platform/intern/s3/S3.kt +++ b/lib/src/main/kotlin/org/veupathdb/lib/compute/platform/intern/s3/S3.kt @@ -147,16 +147,9 @@ internal object S3 { */ @JvmStatic fun wipeWorkspace(jobID: HashID) { - // Create a prefix for the objects to delete based on the root path in MinIO - // plus the job ID. - // - // Because the s3 workspaces lib allows for leading slash but MinIO itself - // does not, remove any leading slash. - val searchPrefix = config.rootPath.stripLeadingSlash().appendSlash() + jobID.toString() - s3.buckets[BucketName(config.bucket)]!! .objects - .list(searchPrefix) + .list(jobID.toS3Prefix()) .forEach { it.delete() } } @@ -336,7 +329,18 @@ internal object S3 { .filterNotNull() } - private fun String.stripLeadingSlash() = if (startsWith('/')) this.substring(1) else this + private fun HashID.toS3Prefix() = + // If the whole root path is just a slash, ignore it, leading slashes are + // not allowed in raw s3 prefix queries + if (config.rootPath == "/" || config.rootPath.isBlank()) + toString() + // If the root path starts with a slash, remove it, leading slashes are not + // allowed in raw s3 prefix queries + else if (config.rootPath[0] == '/') + config.rootPath.substring(1).appendSlash() + toString() + else + config.rootPath.appendSlash() + toString() + private fun String.appendSlash() = if (!endsWith('/'))