File tree Expand file tree Collapse file tree 5 files changed +22
-6
lines changed
common/src/aws/smithy/kotlin/runtime/util
src/aws/smithy/kotlin/runtime/util
test/aws/smithy/kotlin/runtime/util
native/src/aws/smithy/kotlin/runtime/util Expand file tree Collapse file tree 5 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -1583,6 +1583,7 @@ public abstract interface class aws/smithy/kotlin/runtime/util/EnvironmentProvid
15831583
15841584public abstract interface class aws/smithy/kotlin/runtime/util/Filesystem {
15851585 public static final field Companion Laws/smithy/kotlin/runtime/util/Filesystem$Companion;
1586+ public abstract fun fileExists (Ljava/lang/String;)Z
15861587 public abstract fun getFilePathSeparator ()Ljava/lang/String;
15871588 public abstract fun readFileOrNull (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
15881589 public abstract fun writeFile (Ljava/lang/String;[BLkotlin/coroutines/Continuation;)Ljava/lang/Object;
Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ public interface Filesystem {
3131 */
3232 public suspend fun writeFile (path : String , data : ByteArray )
3333
34+ /* *
35+ * Check if a file exists at the [path].
36+ * @param path fully qualified path encoded specifically to the target platform's filesystem
37+ */
38+ public fun fileExists (path : String ): Boolean
39+
3440 public companion object {
3541 /* *
3642 * Construct a fake filesystem from a mapping of paths to contents
@@ -48,4 +54,5 @@ internal class MapFilesystem(
4854 override suspend fun writeFile (path : String , data : ByteArray ) {
4955 memFs[path] = data
5056 }
57+ override fun fileExists (path : String ): Boolean = memFs[path] != null
5158}
Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ internal actual object SystemDefaultProvider : PlatformProvider {
4848 }
4949 }
5050
51+ override fun fileExists (path : String ): Boolean = File (path).exists()
52+
5153 public suspend fun readFileOrNull (path : Path ): ByteArray? = readFileOrNull(path.toAbsolutePath().toString())
5254 public suspend fun readFileOrNull (file : File ): ByteArray? = readFileOrNull(file.absolutePath)
5355
Original file line number Diff line number Diff line change 44 */
55package aws.smithy.kotlin.runtime.util
66
7- import kotlinx.coroutines.runBlocking
7+ import kotlinx.coroutines.test.runTest
88import java.nio.file.Files
99import java.nio.file.Path
1010import kotlin.io.path.absolutePathString
1111import kotlin.io.path.writeText
12- import kotlin.test.BeforeTest
13- import kotlin.test.Test
14- import kotlin.test.assertEquals
15- import kotlin.test.assertNotNull
12+ import kotlin.test.*
1613
1714class PlatformJVMTest {
1815
@@ -26,7 +23,7 @@ class PlatformJVMTest {
2623 }
2724
2825 @Test
29- fun itReadsFiles () = runBlocking {
26+ fun itReadsFiles () = runTest {
3027 val actual = PlatformProvider .System .readFileOrNull(tempFile.absolutePathString())
3128
3229 assertNotNull(actual)
@@ -49,4 +46,9 @@ class PlatformJVMTest {
4946 val allPropertiesFromPlatform = PlatformProvider .System .getAllProperties()
5047 assertEquals(allPropertiesFromSystem, allPropertiesFromPlatform)
5148 }
49+
50+ @Test
51+ fun testFileExists () = runTest {
52+ assertTrue(PlatformProvider .System .fileExists(tempFile.absolutePathString()))
53+ }
5254}
Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ internal actual object SystemDefaultProvider : PlatformProvider {
2424 TODO (" Not yet implemented" )
2525 }
2626
27+ override fun fileExists (path : String ): Boolean {
28+ TODO (" Not yet implemented" )
29+ }
30+
2731 override fun osInfo (): OperatingSystem {
2832 TODO (" Not yet implemented" )
2933 }
You can’t perform that action at this time.
0 commit comments