summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java')
-rw-r--r--src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java b/src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java
index 29b7090..1baa994 100644
--- a/src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java
+++ b/src/main/java/org/openslx/imagemaster/crcchecker/CRCChecker.java
@@ -8,6 +8,7 @@ import java.util.zip.CRC32;
import org.apache.log4j.Logger;
import org.openslx.imagemaster.Globals;
+// TODO: Move to master-sync-shared, sattelite daemon might want to check images too
public class CRCChecker
{
@@ -19,7 +20,7 @@ public class CRCChecker
* @param imageFile The imageFile to check
* @param crcFile The crcFile to check against
* @param blocks The blocks to check
- * @return The blocks where the crc was right
+ * @return List of blocks where the crc matches, or null if the crc file is corrupted
*/
public static List<Integer> checkCRC(String imageFile, String crcFile, List<Integer> blocks) throws IOException
{
@@ -30,12 +31,15 @@ public class CRCChecker
log.debug( "Checking image file: '" + imageFile + "' with crc file: '" + crcFile + "'");
try {
- if (!crc.isValid()) return result; // TODO: this needs to be handled in another way
+ if (!crc.isValid()) return null;
+ // TODO: also return null if the crc file contains the wrong number of checksums (only makes sense if the upload is complete)
} catch (IOException e) {
throw new IOException( "Could not read CRC file", e );
}
// file is smaller than one block - no need to check crc yet
+ // TODO: Needs more logic, if the image is complete and < 16MB, we still need to check the block.
+ // The caller should make sure to only check crc of blocks that are finished downloading
if (image.length() < Globals.blockSize) {
return result;
}
@@ -43,6 +47,9 @@ public class CRCChecker
for (Integer blockN : blocks) {
byte[] block;
try {
+ // TODO: For performance improvements maybe prealloc the array outside the loop with a size of Globals.BLOCK_SIZE
+ // and then make getBlock(blockN, block) return the actual size of the block (Should always be BLOCK_SIZE except
+ // for the last block), so you never need to create fresh byte arrays inside the loop
block = image.getBlock( blockN );
} catch ( IOException e ) {
throw new IOException( "Could not read image file", e );