Skip to content

Commit

Permalink
handle special case where entire root path is just a slash
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxcapades committed May 29, 2024
1 parent f9df583 commit 9e58b7a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "org.veupathdb.lib"
version = "1.7.3"
version = "1.7.4"


dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}

Expand Down Expand Up @@ -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('/'))
Expand Down

0 comments on commit 9e58b7a

Please sign in to comment.