retry hashing if an internal error happens

dbus-notify
Zlatin Balevsky 2022-06-08 20:37:28 +01:00
parent cb204a6c79
commit 5365285e73
No known key found for this signature in database
GPG Key ID: A72832072D525E41
1 changed files with 35 additions and 26 deletions

View File

@ -2,7 +2,7 @@ package com.muwire.core.files
import com.muwire.core.InfoHash
import com.muwire.core.util.DataUtil
import groovy.util.logging.Log
import net.i2p.data.Base64
import java.nio.MappedByteBuffer
@ -11,7 +11,9 @@ import java.nio.channels.FileChannel.MapMode
import java.nio.channels.FileLock
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import java.util.logging.Level
@Log
class FileHasher {
public static final int MIN_PIECE_SIZE_POW2 = 17
@ -50,6 +52,8 @@ class FileHasher {
}
InfoHash hashFile(File file) {
while(true) {
try {
final long length = file.length()
final long size = 0x1L << getPieceSize(length)
int numPieces = (length / size).toInteger()
@ -77,7 +81,12 @@ class FileHasher {
}
byte[] hashList = output.toByteArray()
InfoHash.fromHashList(hashList)
return InfoHash.fromHashList(hashList)
} catch (InternalError bad) {
// nothing we can but try again. Happens on jre 18.0.1
log.log(Level.SEVERE,"internal error while hashing", bad)
}
}
}
public static void main(String[] args) {