use of org.dcache.util.ChecksumType in project dcache by dCache.
the class FsInode_CKSTYP method getChecksums.
private String getChecksums() {
StringBuilder sb = new StringBuilder();
ChecksumType[] list = ChecksumType.values();
for (ChecksumType type : list) {
sb.append(type.getName()).append("\n");
}
return sb.toString();
}
use of org.dcache.util.ChecksumType in project dcache by dCache.
the class FsInode_PSET method handleSetChecksum.
/*
* This method allows overwrite only with ROOT access.
* It also allows a non-ROOT user to set only one checksum
* (type, value) pair.
*/
private void handleSetChecksum() throws ChimeraFsException {
if (_args.length != 3) {
throw new InvalidArgumentChimeraException("incorrect number of arguments.");
}
Set<Checksum> checksums = _fs.getInodeChecksums(this);
ChecksumType type = ChecksumType.getChecksumType(_args[1]);
try {
/*
* The filesystem implementation does not allow
* overwrite using the 'setInodeChecksum' method, so
* an explicit deletion is required.
*/
if (checksums.stream().anyMatch(c -> type.equals(c.getType()))) {
_fs.removeInodeChecksum(this, type.getType());
}
Checksum cks = new Checksum(type, _args[2]);
_fs.setInodeChecksum(this, type.getType(), cks.getValue());
} catch (IllegalArgumentException e) {
throw new InvalidArgumentChimeraException("Invalid checksum: " + _args[2] + "; " + e.getMessage());
}
}
use of org.dcache.util.ChecksumType in project dcache by dCache.
the class ChecksumModuleV1 method enforcePostTransferPolicy.
@Override
public void enforcePostTransferPolicy(ReplicaDescriptor handle, Iterable<Checksum> actualChecksums) throws CacheException, NoSuchAlgorithmException, IOException, InterruptedException {
Iterable<Checksum> expectedChecksums = handle.getChecksums();
if (hasPolicy(ON_WRITE) || (hasPolicy(ENFORCE_CRC) && isEmpty(expectedChecksums) && isEmpty(actualChecksums))) {
EnumSet<ChecksumType> types = EnumSet.copyOf(_defaultChecksumType);
expectedChecksums.forEach(c -> types.add(c.getType()));
actualChecksums.forEach(// REVISIT do we really need to recalculate these?
c -> types.add(c.getType()));
List<MessageDigest> digests = types.stream().map(ChecksumType::createMessageDigest).collect(Collectors.toList());
try (RepositoryChannel channel = handle.createChannel()) {
actualChecksums = computeChecksums(channel, digests);
}
}
compareChecksums(expectedChecksums, actualChecksums);
handle.addChecksums(actualChecksums);
}
use of org.dcache.util.ChecksumType in project dcache by dCache.
the class ChecksumModuleV1 method verifyBrokenFile.
@Override
public Set<Checksum> verifyBrokenFile(ReplicaRecord entry, Set<Checksum> expectedChecksums) throws IOException, FileCorruptedCacheException, InterruptedException {
Set<Checksum> additionalChecksums = Collections.emptySet();
switch(entry.getState()) {
case FROM_CLIENT:
EnumSet<ChecksumType> types = EnumSet.noneOf(ChecksumType.class);
expectedChecksums.stream().forEach(c -> types.add(c.getType()));
if (hasPolicy(ON_WRITE) || (hasPolicy(ON_TRANSFER) && hasPolicy(ENFORCE_CRC))) {
types.addAll(_defaultChecksumType);
}
if (!types.isEmpty()) {
List<MessageDigest> digests = types.stream().map(ChecksumType::createMessageDigest).collect(Collectors.toList());
try (RepositoryChannel channel = entry.openChannel(FileStore.O_READ)) {
Set<Checksum> actualChecksums = computeChecksums(channel, digests);
compareChecksums(expectedChecksums, actualChecksums);
additionalChecksums = Sets.difference(actualChecksums, expectedChecksums).copyInto(new HashSet<>());
}
}
}
return additionalChecksums;
}
use of org.dcache.util.ChecksumType in project dcache by dCache.
the class AbstractFtpDoorV1 method buildChecksumList.
private static String buildChecksumList() {
String result = "";
int mod = 0;
for (ChecksumType type : ChecksumType.values()) {
result += type.getName() + ",";
mod = 1;
}
return result.substring(0, result.length() - mod);
}
Aggregations