Skip to content

Commit

Permalink
S3 File head fix for Windows machines.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjsvedin committed Mar 26, 2024
1 parent def48a2 commit 9990319
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Expand Up @@ -38,7 +38,7 @@ data class S3File(val system: S3FileSystem, val path: File) : FileObject {
it.delimiter("/")
token?.let { t -> it.continuationToken(t) }
}.await()
results += r.contents().filter { !it.key().substringAfter(path.toString()).contains('/') }
results += r.contents().filter { !it.key().substringAfter(path.unixPath).contains('/') }
.map { S3File(system, File(it.key())) }
if (r.isTruncated) token = r.nextContinuationToken()
else break
Expand All @@ -53,7 +53,7 @@ data class S3File(val system: S3FileSystem, val path: File) : FileObject {
try {
system.s3Async.headObject {
it.bucket(system.bucket)
it.key(path.toString())
it.key(path.unixPath)
}.await().let {
FileInfo(
type = ContentType(it.contentType()),
Expand Down
Expand Up @@ -14,9 +14,6 @@ import kotlinx.coroutines.withTimeout
import kotlinx.serialization.encodeToString
import org.junit.Assert.*
import org.junit.Test
import kotlin.time.Duration
import kotlinx.datetime.Instant
import java.time.Clock
import kotlin.test.assertContains
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -65,6 +62,17 @@ abstract class FileSystemTests {
assertEquals(ContentType.Text.Plain, info!!.type)
assertTrue(info.size > 0L)
assertTrue(info.lastModified > beforeModify)

// Testing with sub folders.
val secondFile = system.root.resolve("test/secondTest.txt")
val secondMessage = "Hello Second world!"
val secondBeforeModify = now().minus(120.seconds)
secondFile.put(HttpContent.Text(secondMessage, ContentType.Text.Plain))
val secondInfo = secondFile.head()
assertNotNull(secondInfo)
assertEquals(ContentType.Text.Plain, secondInfo!!.type)
assertTrue(secondInfo.size > 0L)
assertTrue(secondInfo.lastModified > secondBeforeModify)
}
}

Expand Down
@@ -1,7 +1,6 @@
package com.lightningkite.lightningdb.test.com.lightningkite.lightningdb.test
package com.lightningkite.lightningdb.test

import com.lightningkite.lightningdb.*
import com.lightningkite.lightningdb.test.*
import com.lightningkite.lightningserver.TestSettings
import com.lightningkite.lightningserver.cache.Cache
import com.lightningkite.lightningserver.cache.CacheTest
Expand All @@ -17,7 +16,6 @@ import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking
import org.junit.Test
import java.io.File
import kotlin.time.Duration
import kotlin.test.assertEquals
import kotlin.time.Duration.Companion.hours

Expand Down
Expand Up @@ -80,9 +80,8 @@ object TestSettings: ServerPathGroup(ServerPath.root) {
com.lightningkite.lightningdb.prepareModels()
Settings.populateDefaults()
engine = LocalEngine(LocalCache)


}

val sampleUser = GlobalScope.async(start = CoroutineStart.LAZY) {
info.collection().insertOne(User(
email = "test@test.com",
Expand Down

0 comments on commit 9990319

Please sign in to comment.