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); } }
/** * Move this item to a new parent, or to a new name, or both * * @param newParent */ public void move(DirectoryNode newParent, String newName) { DirectoryNode oldParent = this.getParent(); if (oldParent != newParent) { this.setParent(newParent); if (oldParent.members != null) { oldParent.members.remove(this); } newParent.getChildren().add(this); setDirty(); newParent.setDirty(); oldParent.setDirty(); } if (!newName.equals(name)) { setName(newName); } parent.checkConsistency(this); }
public void delete() { parent.getChildren().remove(this); parent.checkConsistency(parent); setDirty(); }