android_studio_releases.main.kts: bump version only if content changed

This commit is contained in:
Jakub Chrzanowski 2022-03-08 10:50:47 +01:00
parent bae310e01c
commit 47dcad5a3d
No known key found for this signature in database
GPG Key ID: C39095BFD769862E

View File

@ -84,7 +84,13 @@ frameUrl.fetch { content ->
Item(name, build, version, channel, platformBuild.toString(), platformVersion.toString(), date) Item(name, build, version, channel, platformBuild.toString(), platformVersion.toString(), date)
} }
}.let { }.let {
Content(current.version + 1, it) val version = with (current) {
when (items.hashCode() != it.hashCode()) {
true -> version + 1
false -> version
}
}
Content(version, it)
}.also { }.also {
Persister().write(it, contentFile) Persister().write(it, contentFile)
}.also { (_, items) -> }.also { (_, items) ->
@ -130,12 +136,13 @@ fun <T> String.download(block: (File) -> T) = URL(this).openStream().use { input
File.createTempFile("android-studio", ".zip").also(File::deleteOnExit).let { tempFile -> File.createTempFile("android-studio", ".zip").also(File::deleteOnExit).let { tempFile ->
FileOutputStream(tempFile).use { outputStream -> FileOutputStream(tempFile).use { outputStream ->
println(" Downloading $this to $tempFile") println(" Downloading $this to $tempFile")
val data = ByteArray(1024) ByteArray(1024).let { data ->
var count: Int var count: Int
while (bis.read(data, 0, data.size).also { count = it } != -1) { while (bis.read(data, 0, data.size).also { count = it } != -1) {
outputStream.write(data, 0, count) outputStream.write(data, 0, count)
} }
} }
}
block(tempFile) block(tempFile)
} }
} }