private void recalcHashes(DataNode item) throws IOException { if (item.dirty == null) { return; // not dirty, which means no children are dirty } // only directories have derived hashes if (item instanceof DirectoryNode) { DirectoryNode dirNode = (DirectoryNode) item; for (DataNode child : dirNode) { recalcHashes(child); } ByteArrayOutputStream bout = new ByteArrayOutputStream(); hashCalc.sort(dirNode.getChildren()); String newHash = hashCalc.calcHash(dirNode, bout); item.setHash(newHash); byte[] arrTriplets = bout.toByteArray(); blobStore.setBlob(newHash, arrTriplets); log.info( "recalcHashes: " + item.name + " children:" + dirNode.members.size() + " hash=" + newHash); } }
public List<ITriplet> find(String hash) { // return DataItem.findByHash(hash, session); byte[] arr = blobStore.getBlob(hash); if (arr == null) { return null; } ByteArrayInputStream bin = new ByteArrayInputStream(arr); try { return hashCalc.parseTriplets(bin); } catch (IOException ex) { throw new RuntimeException(ex); } }
public boolean dirExists(String hash) { return blobStore.hasBlob(hash); }