Skip to content

Commit

Permalink
fix: Only write cache after a download finished, forces a re-download…
Browse files Browse the repository at this point in the history
… next time keepup runs

fix: Set infinite timeout on http downloads, not just GitHub
  • Loading branch information
0ffz committed Apr 12, 2024
1 parent 6e5b891 commit 1368876
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kotlin.code.style=official
version=2.0.1
version=2.0.2
13 changes: 10 additions & 3 deletions src/main/kotlin/downloading/HttpDownload.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package downloading

import io.ktor.client.*
import io.ktor.client.plugins.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
Expand All @@ -25,13 +26,19 @@ class HttpDownload(
val cache = "Last-Modified: $lastModified, Content-Length: $length"
if (targetFile.exists() && cacheFile.exists() && cacheFile.readText() == cache)
return listOf(DownloadResult.SkippedBecauseCached(targetFile, source.keyInConfig))
cacheFile.deleteIfExists()
cacheFile.createFile().writeText(cache)

client.get(source.query)
client.get(source.query) {
timeout {
requestTimeoutMillis = HttpTimeout.INFINITE_TIMEOUT_MS
}
}
.bodyAsChannel()
.copyAndClose(targetFile.toFile().writeChannel())

// Only mark as cached after download is complete
cacheFile.deleteIfExists()
cacheFile.createFile().writeText(cache)

return listOf(DownloadResult.Downloaded(targetFile, source.keyInConfig))
}
}

0 comments on commit 1368876

Please sign in to comment.