Skip to content

Commit

Permalink
Merge pull request #128 from DICE-UNC/issue87
Browse files Browse the repository at this point in the history
Issue87
  • Loading branch information
michael-conway committed Jun 9, 2015
2 parents b223a0e + f6979f8 commit 77d967e
Show file tree
Hide file tree
Showing 22 changed files with 1,129 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class AbstractChecksumComputeStrategy {
* @throws FileNotFoundException
* @throws JargonException
*/
public abstract ChecksumValue instanceChecksumForPackingInstruction(
public abstract ChecksumValue computeChecksumValueForLocalFile(
final String localFileAbsolutePath) throws FileNotFoundException,
JargonException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.irods.jargon.core.checksum;

import org.irods.jargon.core.connection.IRODSSession;
import org.irods.jargon.core.protovalues.ChecksumEncodingEnum;

/**
* Factory interface to create methods to compute local checksums based on a
* type that can be derived from the {@link ChecksumManager}.
* <p/>
* This factory is available from the {@link IRODSSession}
*
* @author Mike Conway - DICE
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
*/
package org.irods.jargon.core.checksum;

import org.irods.jargon.core.connection.IRODSSession;
import org.irods.jargon.core.protovalues.ChecksumEncodingEnum;

/**
* Factory to create methods to compute local checksums based on a type that can
* be derived from the {@link ChecksumManager}.
* be derived from the {@link ChecksumManager}. *
* <p/>
* This factory is available from the {@link IRODSSession}
*
* @author Mike Conway - DICE
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class MD5LocalChecksumComputerStrategy extends
* instanceChecksumForPackingInstruction(java.lang.String)
*/
@Override
public ChecksumValue instanceChecksumForPackingInstruction(
public ChecksumValue computeChecksumValueForLocalFile(
final String localFileAbsolutePath) throws FileNotFoundException,
JargonException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SHA256LocalChecksumComputerStrategy extends
* instanceChecksumForPackingInstruction(java.lang.String)
*/
@Override
public ChecksumValue instanceChecksumForPackingInstruction(
public ChecksumValue computeChecksumValueForLocalFile(
final String localFileAbsolutePath) throws FileNotFoundException,
JargonException {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
*
*/
package org.irods.jargon.core.exception;

/**
* @author Mike Conway - DICE General exception for checksum mismatches
*
*/
public class ChecksumInvalidException extends JargonException {

private static final long serialVersionUID = 6069493884085439471L;

/**
* @param message
*/
public ChecksumInvalidException(String message) {
super(message);
}

/**
* @param message
* @param cause
*/
public ChecksumInvalidException(String message, Throwable cause) {
super(message, cause);
}

/**
* @param cause
*/
public ChecksumInvalidException(Throwable cause) {
super(cause);
}

/**
* @param message
* @param cause
* @param underlyingIRODSExceptionCode
*/
public ChecksumInvalidException(String message, Throwable cause,
int underlyingIRODSExceptionCode) {
super(message, cause, underlyingIRODSExceptionCode);
// TODO Auto-generated constructor stub
}

/**
* @param cause
* @param underlyingIRODSExceptionCode
*/
public ChecksumInvalidException(Throwable cause,
int underlyingIRODSExceptionCode) {
super(cause, underlyingIRODSExceptionCode);
}

/**
* @param message
* @param underlyingIRODSExceptionCode
*/
public ChecksumInvalidException(String message,
int underlyingIRODSExceptionCode) {
super(message, underlyingIRODSExceptionCode);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ ChecksumValue computeLocalFileChecksum(final File localFile,
.getIrodsSession().getLocalChecksumComputerFactory()
.instance(checksumEncoding);
try {
return strategy.instanceChecksumForPackingInstruction(localFile
return strategy.computeChecksumValueForLocalFile(localFile
.getAbsolutePath());
} catch (FileNotFoundException e) {
log.error("cannot find file for computing local checksum", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3096,7 +3096,7 @@ public boolean verifyChecksumBetweenLocalAndIrods(
ChecksumValue localChecksum = getIRODSSession()
.getLocalChecksumComputerFactory()
.instance(irodsChecksum.getChecksumEncoding())
.instanceChecksumForPackingInstruction(
.computeChecksumValueForLocalFile(
localFile.getAbsolutePath());
log.info("localChecksum:{}", localChecksum);
return irodsChecksum.getChecksumStringValue().equals(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.irods.jargon.core.pub;

import org.irods.jargon.core.checksum.ChecksumValue;
import org.irods.jargon.core.exception.ChecksumInvalidException;
import org.irods.jargon.core.exception.FileNotFoundException;
import org.irods.jargon.core.exception.JargonException;
import org.irods.jargon.core.pub.domain.ObjStat;
Expand Down Expand Up @@ -48,4 +49,25 @@ ChecksumValue computeChecksumValueFromIrodsData(String irodsValue)
ChecksumValue computeChecksumOnDataObject(IRODSFile irodsFile)
throws JargonException;

/**
* Compare a local file against iRODS using the configured checksum algo on
* the iRODS side. Return the checksum information, or throw an exception if
* the checksums do not match
*
* @param localAbsolutePath
* <code>String</code> with the local file absolute path
* @param irodsAbsolutePath
* <code>String</code> with the irods file absolute path
* @return {@link ChecksumValue} for a validated checksum
* @throws FileNotFoundException
* if either file is missing
* @throws ChecksumInvalidException
* if the checksums do not match
* @throws JargonException
*/
ChecksumValue verifyLocalFileAgainstIrodsFileChecksum(
final String localAbsolutePath, final String irodsAbsolutePath)
throws FileNotFoundException, ChecksumInvalidException,
JargonException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
*/
package org.irods.jargon.core.pub;

import java.io.File;

import org.irods.jargon.core.checksum.AbstractChecksumComputeStrategy;
import org.irods.jargon.core.checksum.ChecksumManager;
import org.irods.jargon.core.checksum.ChecksumManagerImpl;
import org.irods.jargon.core.checksum.ChecksumValue;
import org.irods.jargon.core.connection.IRODSAccount;
import org.irods.jargon.core.connection.IRODSSession;
import org.irods.jargon.core.exception.ChecksumInvalidException;
import org.irods.jargon.core.exception.FileNotFoundException;
import org.irods.jargon.core.exception.JargonException;
import org.irods.jargon.core.packinstr.DataObjInp;
Expand Down Expand Up @@ -124,4 +128,81 @@ public ChecksumValue computeChecksumValueFromIrodsData(
.determineChecksumEncodingFromIrodsData(irodsValue.trim());
}

/*
* (non-Javadoc)
*
* @see org.irods.jargon.core.pub.DataObjectChecksumUtilitiesAO#
* verifyLocalFileAgainstIrodsFileChecksum(java.lang.String,
* java.lang.String)
*/
@Override
public ChecksumValue verifyLocalFileAgainstIrodsFileChecksum(
final String localAbsolutePath, final String irodsAbsolutePath)
throws FileNotFoundException, ChecksumInvalidException,
JargonException {
log.info("verifyLocalFileAgainstIrodsFileChecksum()");
if (localAbsolutePath == null || localAbsolutePath.isEmpty()) {
throw new IllegalArgumentException(
"null or empty localAbsolutePath");
}

if (irodsAbsolutePath == null || irodsAbsolutePath.isEmpty()) {
throw new IllegalArgumentException(
"null or empty irodsAbsolutePath");
}

log.info("localAbsolutePath:{}", localAbsolutePath);
log.info("irodsAbsolutePath:{}", irodsAbsolutePath);

File localFile = new File(localAbsolutePath);

if (!localFile.exists()) {
throw new FileNotFoundException("local file does not exist");
}

if (!localFile.isFile()) {
throw new JargonException(
"local file is not a file, it is a collection");
}

IRODSFile irodsFile = this.getIRODSFileFactory().instanceIRODSFile(
irodsAbsolutePath);

if (!irodsFile.exists()) {
throw new FileNotFoundException("irods file does not exist");
}

if (!irodsFile.isFile()) {
throw new JargonException(
"irods file is not a file, it is a collection");
}

ChecksumValue checksumValue = this
.computeChecksumOnDataObject(irodsFile);

AbstractChecksumComputeStrategy checksumComputeStrategy = this
.getIRODSSession().getLocalChecksumComputerFactory()
.instance(checksumValue.getChecksumEncoding());
ChecksumValue localValue;
try {
localValue = checksumComputeStrategy
.computeChecksumValueForLocalFile(localAbsolutePath);
} catch (java.io.FileNotFoundException e) {
// Jargon has it's own file not found exception, dumb or not
throw new FileNotFoundException(
"local file not found during checksum");
}

if (!localValue.equals(checksumValue)) {
log.error("checksum mismatch");
log.error("local checksum:{}", localValue);
log.error("irods checksum:{}", checksumValue);
throw new ChecksumInvalidException(
"checksum mismatch between local and iRODS");
}

return checksumValue;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ private int openIRODSFile() throws JargonException {
@Override
public int read() throws IOException {
try {
// openFile();
byte buffer[] = new byte[1];

int temp = fileIOOperations.fileRead(fd, buffer, 0, 1);
Expand Down Expand Up @@ -296,7 +295,6 @@ public int read(final byte b[], final int off, final int len)

int temp;
try {
// openFile();
temp = fileIOOperations.fileRead(fd, b, off, len);
} catch (JargonException e) {
log.error(
Expand Down Expand Up @@ -360,7 +358,6 @@ public int read(final byte b[], final int off, final int len)
*/
@Override
public int read(final byte b[]) throws IOException {
// openFile();
return read(b, 0, b.length);
}

Expand Down
Loading

0 comments on commit 77d967e

Please sign in to comment.