Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import io.ktor.client.request.post
import io.ktor.client.request.preparePost
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.http.contentType
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.readUTF8Line
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.serialization.json.Json
import me.devnatan.dockerkt.io.requestCatching
import me.devnatan.dockerkt.models.image.ImageBuildOptions
import me.devnatan.dockerkt.models.image.ImagePull
import me.devnatan.dockerkt.models.image.ImageSummary
Expand Down Expand Up @@ -51,9 +53,13 @@ public class ImageResource internal constructor(
force: Boolean? = false,
noprune: Boolean? = false,
) {
httpClient.delete("$BasePath/$name") {
parameter("force", force)
parameter("noprune", noprune)
requestCatching(
HttpStatusCode.NotFound to { exception -> ImageNotFoundException(exception, name) },
) {
httpClient.delete("$BasePath/$name") {
parameter("force", force)
parameter("noprune", noprune)
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/commonTest/kotlin/me/devnatan/dockerkt/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import me.devnatan.dockerkt.models.volume.Volume
import me.devnatan.dockerkt.models.volume.VolumeCreateOptions
import me.devnatan.dockerkt.resource.container.create
import me.devnatan.dockerkt.resource.container.remove
import me.devnatan.dockerkt.resource.image.ImageNotFoundException
import me.devnatan.dockerkt.resource.volume.create
import me.devnatan.dockerkt.resource.volume.remove
import kotlin.test.fail
Expand All @@ -23,7 +24,9 @@ suspend fun <R> DockerClient.withImage(
try {
return block(imageName)
} finally {
images.remove(imageName, force = true)
try {
images.remove(imageName, force = true)
} catch (_: ImageNotFoundException) {}
}
}

Expand Down
Loading