summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster
diff options
context:
space:
mode:
authorNils Schwabe2014-07-23 14:21:46 +0200
committerNils Schwabe2014-07-23 14:21:46 +0200
commit9b2d4f939e2246c02376f8d8a1c0fca5ff001920 (patch)
tree4b27cd5d6f4c57cb7d25faa1495d17fc6c8258ee /src/main/java/org/openslx/imagemaster
parent[thrift] Add flag to UploadInfos to tell satellite if all blocks are valid (diff)
downloadmaster-sync-shared-9b2d4f939e2246c02376f8d8a1c0fca5ff001920.tar.gz
master-sync-shared-9b2d4f939e2246c02376f8d8a1c0fca5ff001920.tar.xz
master-sync-shared-9b2d4f939e2246c02376f8d8a1c0fca5ff001920.zip
[CRCFile] Fix bug where sums are checked
Diffstat (limited to 'src/main/java/org/openslx/imagemaster')
-rw-r--r--src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java b/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java
index a096bf6..807aac1 100644
--- a/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java
+++ b/src/main/java/org/openslx/imagemaster/crcchecker/CRCFile.java
@@ -71,19 +71,16 @@ public class CRCFile
{
if ( listOfCrcSums == null || listOfCrcSums.isEmpty() )
return false;
- int masterSum = listOfCrcSums.remove( 0 );
- byte[] bytesOfInt;
+
+ int masterSum = listOfCrcSums.get( 0 ); // don't use the first sum for the calculation because it is the sum over the other sums
int size = listOfCrcSums.size();
- byte[] bytes = new byte[ size * Integer.SIZE / 8 ];
- for ( int i = 0; i < size; i++ ) {
- bytesOfInt = ByteBuffer.allocate( 4 ).putInt( listOfCrcSums.remove( 0 ) ).array(); // get the bytes of this integer
- bytes[4 * i] = bytesOfInt[0];
- bytes[4 * i + 1] = bytesOfInt[1];
- bytes[4 * i + 2] = bytesOfInt[2];
- bytes[4 * i + 3] = bytesOfInt[3];
- }
+
CRC32 crcCalc = new CRC32();
- crcCalc.update( bytes );
+
+ for ( int i = 1; i < size; i++ ) {
+ crcCalc.update( ByteBuffer.allocate( 4 ).putInt( listOfCrcSums.get( i ) ).array() ); // update the crc calculator with the next 4 bytes of the integer
+ }
+
return ( masterSum == Integer.reverseBytes( (int)crcCalc.getValue() ) );
}
@@ -150,7 +147,7 @@ public class CRCFile
}
dis.close();
}
-
+
public int getMasterSum() throws IOException
{
if ( crcSums == null )