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

Change md5 implementation to checksum timestamps instead of files.

This commit is contained in:
Cedric Beust 2016-06-07 21:09:11 -08:00
parent 5587eb33bc
commit a9b8594a83

View file

@ -18,7 +18,13 @@ public class Md5 {
// return DatatypeConverter.printHexBinary(md5.digest()).toLowerCase()
// }
fun toMd5Directories(directories: List<File>) : String? {
/**
* Calculate a checksum for all the files under the passed directories. The conversion from File to
* bytes can be customized by the @param{toBytes} parameter. The default implementation calculates
* a checksum of the last modified timestamp.
*/
fun toMd5Directories(directories: List<File>,
toBytes: (File) -> ByteArray = { it.lastModified().toString().toByteArray() } ): String? {
val ds = directories.filter { it.exists() }
if (ds.size > 0) {
MessageDigest.getInstance("MD5").let { md5 ->
@ -37,7 +43,7 @@ public class Md5 {
it.isFile
}.forEach {
fileCount++
val bytes = it.readBytes()
val bytes = toBytes(it)
md5.update(bytes, 0, bytes.size)
}
}