-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from at88mph/size-fix
Fix for proper content length checking
- Loading branch information
Showing
5 changed files
with
38 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
## deployable containers have a semantic and build tag | ||
# semantic version tag: major.minor | ||
# build version tag: timestamp | ||
VERSION="1.1.2" | ||
VERSION="1.1.3" | ||
TAGS="${VERSION} ${VERSION}-$(date -u +"%Y%m%dT%H%M%S")" | ||
unset VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,42 +70,32 @@ | |
|
||
import ca.nrc.cadc.util.HexUtil; | ||
import ca.nrc.cadc.util.StringUtil; | ||
import org.opencadc.vospace.Node; | ||
import org.opencadc.vospace.NodeProperty; | ||
import org.opencadc.vospace.VOS; | ||
import net.canfar.storage.UploadVerificationFailedException; | ||
|
||
import java.net.URI; | ||
|
||
|
||
public class UploadVerifier { | ||
|
||
/** | ||
* Verify that each byte is accounted for on the server side. | ||
* | ||
* @param byteCount The count of bytes. | ||
* @param node The node to verify. | ||
* @param calculatedByteCount The count of bytes. | ||
* @param serverByteCount The server reported byte count. | ||
* @throws UploadVerificationFailedException Any upload error, such as bad filename. | ||
*/ | ||
public void verifyByteCount(final long byteCount, final Node node) | ||
public void verifyByteCount(final long calculatedByteCount, final long serverByteCount) | ||
throws UploadVerificationFailedException { | ||
if (byteCount < 0) { | ||
if (calculatedByteCount < 0) { | ||
throw new IllegalArgumentException("The given byte count cannot be a negative value."); | ||
} else if (node == null) { | ||
throw new IllegalArgumentException("The given Node cannot be null."); | ||
} else if (serverByteCount < 0) { | ||
throw new IllegalArgumentException("The server byte count cannot be a negative value."); | ||
} | ||
|
||
final NodeProperty contentLengthProperty = node.getProperty(VOS.PROPERTY_URI_CONTENTLENGTH); | ||
final long contentLength = contentLengthProperty == null | ||
? 0L | ||
: Long.parseLong(contentLengthProperty.getValue()); | ||
|
||
if (byteCount != contentLength) { | ||
if (calculatedByteCount != serverByteCount) { | ||
throw new UploadVerificationFailedException("** ERROR ** - Upload did not succeed: " | ||
+ String.format("File length counted [%d] does not " | ||
+ "match what the service said it " | ||
+ "should be [%d]", byteCount, | ||
contentLength)); | ||
+ "should be [%d]", calculatedByteCount, | ||
serverByteCount)); | ||
} | ||
} | ||
|
||
|
@@ -116,29 +106,25 @@ public void verifyByteCount(final long byteCount, final Node node) | |
* the string will be compared to what the returned Node provided. | ||
* | ||
* @param calculatedMD5 The byte array of the calculated MD5. | ||
* @param node The node to verify against. | ||
* @param serverMD5 The server reported MD5. | ||
* @throws UploadVerificationFailedException Any upload error, such as bad filename. | ||
*/ | ||
public void verifyMD5(final byte[] calculatedMD5, final Node node) throws UploadVerificationFailedException { | ||
public void verifyMD5(final byte[] calculatedMD5, final String serverMD5) | ||
throws UploadVerificationFailedException { | ||
if (calculatedMD5 == null) { | ||
throw new IllegalArgumentException("The calculated MD5 cannot be null."); | ||
} else if (node == null) { | ||
throw new IllegalArgumentException("The given Node cannot be null."); | ||
} else if (serverMD5 == null) { | ||
throw new IllegalArgumentException("The server MD5 cannot be null."); | ||
} | ||
|
||
final NodeProperty MD5Property = node.getProperty(VOS.PROPERTY_URI_CONTENTMD5); | ||
final String serverMD5String = MD5Property == null | ||
? null | ||
: MD5Property.getValue(); | ||
|
||
if (!StringUtil.hasLength(serverMD5String)) { | ||
if (!StringUtil.hasLength(serverMD5)) { | ||
throw new UploadVerificationFailedException("** ERROR YOUR UPLOAD DID NOT SUCCEED ** " | ||
+ "MD5 checksum was not produced by " | ||
+ "service! This was not expected, please " | ||
+ "contact [email protected] for " | ||
+ "assistance."); | ||
} else { | ||
if (!HexUtil.toHex(calculatedMD5).equals(serverMD5String)) { | ||
if (!HexUtil.toHex(calculatedMD5).equals(serverMD5)) { | ||
throw new UploadVerificationFailedException( | ||
"** ERROR ** - Upload did not succeed: " | ||
+ "MD5 checksum failed."); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters