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 DataNode find(Path path) { if (path.isRoot()) { return rootDataNode; } else { DataNode parent = find(path.getParent()); if (parent == null) { return null; } else if (parent instanceof DirectoryNode) { DirectoryNode dirNode = (DirectoryNode) parent; return dirNode.get(path.getName()); } else { return null; } } }
/** * 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); }
protected void setDirty() { if (dirty != null) { return; // already set } dirty = Boolean.TRUE; if (parent != null) { parent.setDirty(); } }
@Override public void copy(DirectoryNode newDir, String newName) { newDir.addFile(newName, this.hash); }
public void delete() { parent.getChildren().remove(this); parent.checkConsistency(parent); setDirty(); }