storeDirectory(getDirectoryStorage(project), newDir);
return true;
}
public static void sanityCheck(BlobStore blobStore, FileData.Builder file) {
Hasher md5 = Hashing.md5().newHasher();
try (HashingOutputStream hos = new HashingOutputStream(ByteStreams.nullOutputStream(), md5)) {
List<FileRange> ranges = file.getRangesList();
for (int i = 0; i < ranges.size(); i++) {
FileRange range = ranges.get(i);
BlobData blob = blobStore.find(range.getContentKey());
if (blob == null) {
throw new IllegalStateException("Unable to find blob for range: " + range);
}
log.debug("Sanity check: fetch blob {}", Hex.toHex(range.getContentKey().toByteArray()));
if (blob.size() != (range.getEnd() - range.getStart())) {
throw new IllegalStateException();
}
blob.copyTo(hos);
if (i != 0) {
FileRange prev = ranges.get(i - 1);
if (prev.getEnd() != range.getStart()) {
throw new IllegalStateException();
}
} else {
if (range.getStart() != 0) {
throw new IllegalStateException();
}
}
if (i == (ranges.size() - 1)) {
if (range.getEnd() != file.getLength()) {
throw new IllegalStateException();
}
}
}
} catch (IOException e) {
throw new IllegalStateException("Error checking file: " + file, e);
}
ByteString hash = ByteString.copyFrom(md5.hash().asBytes());
if (!file.getHash().equals(hash)) {
log.warn("Hash mismatch: {} vs {}", Hex.toHex(file.getHash().toByteArray()), Hex.toHex(hash.toByteArray()));
throw new IllegalStateException("Hash mismatch");
}