Не подтверждена Коммит f7317b30 создал по автору Rustam's avatar Rustam Зафиксировано автором GitHub
Просмотр файлов

KTOR-4707 Fix check for existence in LocalFileContent (#3117)

владелец 1d419232
......@@ -25,10 +25,10 @@ public class LocalFileContent(
override val contentLength: Long get() = file.length()
init {
val lastModifiedVersion = file.lastModified()
if (lastModifiedVersion == 0L) {
if (!file.exists()) {
throw IOException("No such file ${file.absolutePath}")
} else {
val lastModifiedVersion = file.lastModified()
versions += LastModifiedVersion(lastModifiedVersion)
}
}
......
/*
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
package io.ktor.tests.http.content
import io.ktor.server.http.content.*
import java.io.*
import kotlin.test.*
class LocalFileContentTest {
@Test
fun testCreateWithFile() {
val file = File.createTempFile("test", "txt")
LocalFileContent(file)
}
@Test
fun testCreateWithFileZeroLastModifiedDate() {
val file = File.createTempFile("test-zero-date", "txt")
file.setLastModified(0)
LocalFileContent(file)
}
@Test
fun testCreateWithNonExistingFile() {
val file = File("test-doesnt-exist", "txt")
assertFailsWith<IOException> {
LocalFileContent(file)
}
}
}
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать