@@ -131,7 +131,11 @@ private fun processCoopMap(
131131 else it.copyTo(target)
132132 }
133133
134- val files = tmp.walk().filter { it.isRegularFile() }.toList()
134+ val files = tmp.walk()
135+ .filter { it.isRegularFile() }
136+ // Files.walk does not guarantee fixed order, but we need it
137+ .sortedBy { tmp.relativize(it).toString() }
138+ .toList()
135139 val currentVersion = db.getLatestVersion(map)
136140
137141 val currentZip = Path .of(mapsDir, map.zipName(currentVersion))
@@ -175,11 +179,16 @@ private fun createZip(
175179 val rel = base.relativize(file)
176180 val entryPath = " /${map.folderName(version)} /$rel "
177181
178- val bytes = file.readText()
179- .replace(
180- " /maps/${map.folderName} /" ,
181- " /maps/${map.folderName(version)} /"
182- ).toByteArray()
182+ val bytes: ByteArray = if (file.isTextFile()) {
183+ file.readText()
184+ .replace(
185+ " /maps/${map.folderName} /" ,
186+ " /maps/${map.folderName(version)} /" ,
187+ )
188+ .toByteArray()
189+ } else {
190+ file.readBytes()
191+ }
183192
184193 val entry = ZipArchiveEntry (entryPath).apply {
185194 // Ensure deterministic times
@@ -200,6 +209,9 @@ private fun createZip(
200209 }
201210}
202211
212+ private fun Path.isTextFile () = listOf (" .md" , " .lua" , " .json" , " .txt" ).any { it.endsWith(it) }
213+
214+
203215private fun md5 (path : Path ): String {
204216 val md = MessageDigest .getInstance(" MD5" )
205217 md.update(path.readBytes())
0 commit comments