/** * Check whether this is the root inode. */ final boolean isRoot() { return getLocalNameBytes().length == 0; }
@Override public byte[] getLocalNameBytes() { return referred.getLocalNameBytes(); }
@Override public final byte[] getKey() { return getLocalNameBytes(); }
void setTarget(INode target, byte[][] targetParentPath) { targetPath = new byte[targetParentPath.length + 1][]; System.arraycopy(targetParentPath, 0, targetPath, 0, targetParentPath.length); targetPath[targetPath.length - 1] = target.getLocalNameBytes(); }
/** Check if a given inode name is reserved */ public static boolean isReservedName(INode inode) { return CHECK_RESERVED_FILE_NAMES && Arrays.equals(inode.getLocalNameBytes(), DOT_RESERVED); }
void setSource(INode source, byte[][] sourceParentPath) { Preconditions.checkState(sourcePath == null); sourcePath = new byte[sourceParentPath.length + 1][]; System.arraycopy(sourceParentPath, 0, sourcePath, 0, sourceParentPath.length); sourcePath[sourcePath.length - 1] = source.getLocalNameBytes(); }
/** * @return null if the local name is null; otherwise, return the local name. */ public final String getLocalName() { final byte[] name = getLocalNameBytes(); return name == null? null: DFSUtil.bytes2String(name); }
@Override public int compare(INode n1, INode n2) { return n1.compareTo(n2.getLocalNameBytes()); } });
/** Serialize {@link #created} */ private void writeCreated(DataOutput out) throws IOException { final List<INode> created = getCreatedUnmodifiable(); out.writeInt(created.size()); for (INode node : created) { // For INode in created list, we only need to record its local name byte[] name = node.getLocalNameBytes(); out.writeShort(name.length); out.write(name); } }
@Override public final int compareTo(byte[] bytes) { return DFSUtilClient.compareBytes(getLocalNameBytes(), bytes); }
/** * Remove the specified child from this directory. * The basic remove method which actually calls children.remove(..). * * @param child the child inode to be removed * * @return true if the child is removed; false if the child is not found. */ public boolean removeChild(final INode child) { final int i = searchChildren(child.getLocalNameBytes()); if (i < 0) { return false; } final INode removed = children.remove(i); Preconditions.checkState(removed == child); return true; }
public boolean addChild(INode node) { final int low = searchChildren(node.getLocalNameBytes()); if (low >= 0) { return false; } addChild(node, low); return true; }
public byte[][] getPathComponents() { int n = 0; for (INode inode = this; inode != null; inode = inode.getParent()) { n++; } byte[][] components = new byte[n][]; for (INode inode = this; inode != null; inode = inode.getParent()) { components[--n] = inode.getLocalNameBytes(); } return components; }
@Override public int compare(INode left, INode right) { if (left == null) { return right == null ? 0 : -1; } else { if (right == null) { return 1; } else { int cmp = compare(left.getParent(), right.getParent()); return cmp == 0 ? SignedBytes.lexicographicalComparator().compare( left.getLocalNameBytes(), right.getLocalNameBytes()) : cmp; } } } };
/** Used to record the modification of a symlink node */ public INode saveChild2Snapshot(INodeDirectory currentINode, final INode child, final int latestSnapshotId, final INode snapshotCopy) { Preconditions.checkArgument(!child.isDirectory(), "child is a directory, child=%s", child); Preconditions.checkArgument(latestSnapshotId != Snapshot.CURRENT_STATE_ID); final DirectoryDiff diff = diffs.checkAndAddLatestSnapshotDiff( latestSnapshotId, currentINode); if (diff.getChild(child.getLocalNameBytes(), false, currentINode) != null) { // it was already saved in the latest snapshot earlier. return child; } diff.diff.modify(snapshotCopy, child); return child; }
private void saveCreatedList(List<INode> created, OutputStream out) throws IOException { // local names of the created list member for (INode c : created) { SnapshotDiffSection.CreatedListEntry.newBuilder() .setName(ByteString.copyFrom(c.getLocalNameBytes())).build() .writeDelimitedTo(out); } }
private INodeSection.INode.Builder buildINodeCommon(INode n) { return INodeSection.INode.newBuilder() .setId(n.getId()) .setName(ByteString.copyFrom(n.getLocalNameBytes())); }
/** * Replace the given child from the created list. * @return true if the child is replaced; false if the child is not found. */ private boolean replaceCreated(final INode oldChild, final INode newChild) { final List<INode> list = getCreatedUnmodifiable(); final int i = search(list, oldChild.getLocalNameBytes()); if (i < 0 || list.get(i).getId() != oldChild.getId()) { return false; } final INode removed = setCreated(i, newChild); Preconditions.checkState(removed == oldChild); return true; }
/** * Caches frequently used file names to reuse file name objects and * reduce heap size. */ void cacheName(INode inode) { // Name is cached only for files if (!inode.isFile()) { return; } ByteArray name = new ByteArray(inode.getLocalNameBytes()); name = nameCache.put(name); if (name != null) { inode.setLocalName(name.getBytes()); } }
SnapshotCopy(INode inode) { this.name = inode.getLocalNameBytes(); this.permission = inode.getPermissionLong(); if (inode.getAclFeature() != null) { aclFeature = AclStorage.addAclFeature(inode.getAclFeature()); } else { aclFeature = null; } this.modificationTime = inode.getModificationTime(); this.accessTime = inode.getAccessTime(); this.xAttrFeature = inode.getXAttrFeature(); }