mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Change md5 implementation to checksum timestamps instead of files.
This commit is contained in:
parent
5587eb33bc
commit
a9b8594a83
1 changed files with 8 additions and 2 deletions
|
@ -18,7 +18,13 @@ public class Md5 {
|
||||||
// return DatatypeConverter.printHexBinary(md5.digest()).toLowerCase()
|
// 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() }
|
val ds = directories.filter { it.exists() }
|
||||||
if (ds.size > 0) {
|
if (ds.size > 0) {
|
||||||
MessageDigest.getInstance("MD5").let { md5 ->
|
MessageDigest.getInstance("MD5").let { md5 ->
|
||||||
|
@ -37,7 +43,7 @@ public class Md5 {
|
||||||
it.isFile
|
it.isFile
|
||||||
}.forEach {
|
}.forEach {
|
||||||
fileCount++
|
fileCount++
|
||||||
val bytes = it.readBytes()
|
val bytes = toBytes(it)
|
||||||
md5.update(bytes, 0, bytes.size)
|
md5.update(bytes, 0, bytes.size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue