コード例 #1
0
 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);
   }
 }
コード例 #2
0
 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;
     }
   }
 }
コード例 #3
0
ファイル: EntryNode.java プロジェクト: aw1621107/hacks
  /**
   * Rename this Entry. This operation will fail if:
   *
   * <p>There is a sibling Entry (i.e., an Entry whose parent is the same as this Entry's parent)
   * with the same name.
   *
   * <p>This Entry is the root of the Entry tree. Its name is dictated by the Filesystem and many
   * not be changed.
   *
   * @param newName the new name for this Entry
   * @return true if the operation succeeded, else false
   */
  public boolean renameTo(final String newName) {
    boolean rval = false;

    if (!isRoot()) {
      rval = _parent.changeName(getName(), newName);
    }
    return rval;
  }
コード例 #4
0
ファイル: EntryNode.java プロジェクト: aw1621107/hacks
  /**
   * Delete this Entry. This operation should succeed, but there are special circumstances when it
   * will not:
   *
   * <p>If this Entry is the root of the Entry tree, it cannot be deleted, as there is no way to
   * create another one.
   *
   * <p>If this Entry is a directory, it cannot be deleted unless it is empty.
   *
   * @return true if the Entry was successfully deleted, else false
   */
  public boolean delete() {
    boolean rval = false;

    if ((!isRoot()) && isDeleteOK()) {
      rval = _parent.deleteEntry(this);
    }
    return rval;
  }
コード例 #5
0
 /**
  * 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);
 }
コード例 #6
0
 protected void setDirty() {
   if (dirty != null) {
     return; // already set
   }
   dirty = Boolean.TRUE;
   if (parent != null) {
     parent.setDirty();
   }
 }
コード例 #7
0
 @Override
 public void copy(DirectoryNode newDir, String newName) {
   newDir.addFile(newName, this.hash);
 }
コード例 #8
0
 public void delete() {
   parent.getChildren().remove(this);
   parent.checkConsistency(parent);
   setDirty();
 }