1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

Download to .tmp files first to fix the dokka-fatjar.jar race condition.

This commit is contained in:
Cedric Beust 2015-11-19 19:57:05 -08:00
parent 05c5cd333f
commit 1c6cf1acc4

View file

@ -8,6 +8,8 @@ import com.google.common.cache.CacheLoader
import com.google.common.cache.LoadingCache import com.google.common.cache.LoadingCache
import com.google.inject.assistedinject.Assisted import com.google.inject.assistedinject.Assisted
import java.io.File import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
import java.util.concurrent.Callable import java.util.concurrent.Callable
import java.util.concurrent.ExecutorService import java.util.concurrent.ExecutorService
import java.util.concurrent.Future import java.util.concurrent.Future
@ -53,19 +55,24 @@ class ArtifactFetcher @Inject constructor(@Assisted("url") val url: String,
if (k.exists) k.string.trim(' ', '\t', '\n').substring(0, 32) if (k.exists) k.string.trim(' ', '\t', '\n').substring(0, 32)
else null else null
val file = File(fileName) val tmpFile = Paths.get(fileName + ".tmp")
file.parentFile.mkdirs() val file = Paths.get(fileName)
urlFactory.create(url).toFile(file) with(tmpFile.toFile()) {
parentFile.mkdirs()
urlFactory.create(url).toFile(this)
}
log(2, "Done downloading, renaming $tmpFile to $file")
Files.move(tmpFile, file)
log(1, " Downloaded $url") log(1, " Downloaded $url")
log(2, " to $file") log(2, " to $tmpFile")
val localMd5 = Md5.toMd5(file) val localMd5 = Md5.toMd5(file.toFile())
if (remoteMd5 != null && remoteMd5 != localMd5) { if (remoteMd5 != null && remoteMd5 != localMd5) {
warn("MD5 not matching for $url") warn("MD5 not matching for $url")
} else { } else {
log(2, "No md5 found for $url, skipping md5 check") log(2, "No md5 found for $url, skipping md5 check")
} }
return file return file.toFile()
} }
} }