/** * @return a new INodesInPath instance that only contains existing INodes. * Note that this method only handles non-snapshot paths. */ public INodesInPath getExistingINodes() { Preconditions.checkState(!isSnapshot()); for (int i = inodes.length; i > 0; i--) { if (inodes[i - 1] != null) { return (i == inodes.length) ? this : getAncestorINodesInPath(i); } } return null; }
/** * @param length number of ancestral INodes in the returned INodesInPath * instance * @return the INodesInPath instance containing ancestral INodes. Note that * this method only handles non-snapshot paths. */ private INodesInPath getAncestorINodesInPath(int length) { Preconditions.checkArgument(length >= 0 && length < inodes.length); Preconditions.checkState(isDotSnapshotDir() || !isSnapshot()); final INode[] anodes = new INode[length]; final byte[][] apath = new byte[length][]; System.arraycopy(this.inodes, 0, anodes, 0, length); System.arraycopy(this.path, 0, apath, 0, length); return new INodesInPath(anodes, apath, isRaw, false, snapshotId); }
void checkTraverse(FSPermissionChecker pc, INodesInPath iip, DirOp dirOp) throws AccessControlException, UnresolvedPathException, ParentNotDirectoryException { final boolean resolveLink; switch (dirOp) { case READ_LINK: case WRITE_LINK: case CREATE_LINK: resolveLink = false; break; default: resolveLink = true; break; } checkTraverse(pc, iip, resolveLink); boolean allowSnapshot = (dirOp == DirOp.READ || dirOp == DirOp.READ_LINK); if (!allowSnapshot && iip.isSnapshot()) { throw new SnapshotAccessControlException( "Modification on a read-only snapshot is disallowed"); } }
final long fileSize = iip.isSnapshot() ? inode.computeFileSize(iip.getPathSnapshotId()) : inode.computeFileSizeNotIncludingLastUcBlock(); if (iip.isSnapshot()) { length, needBlockToken, iip.isSnapshot(), feInfo, ecPolicy); && !iip.isSnapshot() && now > inode.getAccessTime() + fsd.getAccessTimePrecision(); return new GetBlockLocationsResult(updateAccessTime, blocks);
/** * @param length number of ancestral INodes in the returned INodesInPath * instance * @return the INodesInPath instance containing ancestral INodes. Note that * this method only handles non-snapshot paths. */ private INodesInPath getAncestorINodesInPath(int length) { Preconditions.checkArgument(length >= 0 && length < inodes.length); Preconditions.checkState(!isSnapshot()); final INode[] anodes = new INode[length]; final byte[][] apath = new byte[length][]; System.arraycopy(this.inodes, 0, anodes, 0, length); System.arraycopy(this.path, 0, apath, 0, length); return new INodesInPath(anodes, apath, false, snapshotId); }
/** * @return a new INodesInPath instance that only contains exisitng INodes. * Note that this method only handles non-snapshot paths. */ public INodesInPath getExistingINodes() { Preconditions.checkState(!isSnapshot()); int i = 0; for (; i < inodes.length; i++) { if (inodes[i] == null) { break; } } INode[] existing = new INode[i]; byte[][] existingPath = new byte[i][]; System.arraycopy(inodes, 0, existing, 0, i); System.arraycopy(path, 0, existingPath, 0, i); return new INodesInPath(existing, existingPath, false, snapshotId); }
/** * @return a new INodesInPath instance that only contains exisitng INodes. * Note that this method only handles non-snapshot paths. */ public INodesInPath getExistingINodes() { Preconditions.checkState(!isSnapshot()); int i = 0; for (; i < inodes.length; i++) { if (inodes[i] == null) { break; } } INode[] existing = new INode[i]; byte[][] existingPath = new byte[i][]; System.arraycopy(inodes, 0, existing, 0, i); System.arraycopy(path, 0, existingPath, 0, i); return new INodesInPath(existing, existingPath, false, snapshotId); }
INodesInPath resolvePathForWrite(FSPermissionChecker pc, String src, boolean resolveLink) throws UnresolvedLinkException, FileNotFoundException, AccessControlException { INodesInPath iip = resolvePath(pc, src, resolveLink); if (iip.isSnapshot()) { throw new SnapshotAccessControlException( "Modification on a read-only snapshot is disallowed"); } return iip; }
INodesInPath resolvePathForWrite(FSPermissionChecker pc, String src, boolean resolveLink) throws UnresolvedLinkException, FileNotFoundException, AccessControlException { INodesInPath iip = resolvePath(pc, src, resolveLink); if (iip.isSnapshot()) { throw new SnapshotAccessControlException( "Modification on a read-only snapshot is disallowed"); } return iip; }
/** * @param length number of ancestral INodes in the returned INodesInPath * instance * @return the INodesInPath instance containing ancestral INodes. Note that * this method only handles non-snapshot paths. */ private INodesInPath getAncestorINodesInPath(int length) { Preconditions.checkArgument(length >= 0 && length < inodes.length); Preconditions.checkState(!isSnapshot()); final INode[] anodes = new INode[length]; final byte[][] apath = new byte[length][]; System.arraycopy(this.inodes, 0, anodes, 0, length); System.arraycopy(this.path, 0, apath, 0, length); return new INodesInPath(anodes, apath, false, snapshotId); }
/** * @return the INodesInPath of the components in src * @throws UnresolvedLinkException if symlink can't be resolved * @throws SnapshotAccessControlException if path is in RO snapshot */ INodesInPath getINodesInPath4Write(String src, boolean resolveLink) throws UnresolvedLinkException, SnapshotAccessControlException { final byte[][] components = INode.getPathComponents(src); INodesInPath inodesInPath = INodesInPath.resolve(rootDir, components, resolveLink); if (inodesInPath.isSnapshot()) { throw new SnapshotAccessControlException( "Modification on a read-only snapshot is disallowed"); } return inodesInPath; }
/** * @return the INodesInPath of the components in src * @throws UnresolvedLinkException if symlink can't be resolved * @throws SnapshotAccessControlException if path is in RO snapshot */ INodesInPath getINodesInPath4Write(String src, boolean resolveLink) throws UnresolvedLinkException, SnapshotAccessControlException { final byte[][] components = INode.getPathComponents(src); INodesInPath inodesInPath = INodesInPath.resolve(rootDir, components, resolveLink); if (inodesInPath.isSnapshot()) { throw new SnapshotAccessControlException( "Modification on a read-only snapshot is disallowed"); } return inodesInPath; }
final long fileSize = iip.isSnapshot() ? inode.computeFileSize(iip.getPathSnapshotId()) : inode.computeFileSizeNotIncludingLastUcBlock(); boolean isUc = inode.isUnderConstruction(); if (iip.isSnapshot()) { isUc, offset, length, needBlockToken, iip.isSnapshot(), feInfo); && !iip.isSnapshot() && now > inode.getAccessTime() + getAccessTimePrecision(); return new GetBlockLocationsResult(updateAccessTime, blocks);
final long fileSize = iip.isSnapshot() ? inode.computeFileSize(iip.getPathSnapshotId()) : inode.computeFileSizeNotIncludingLastUcBlock(); boolean isUc = inode.isUnderConstruction(); if (iip.isSnapshot()) { isUc, offset, length, needBlockToken, iip.isSnapshot(), feInfo); && !iip.isSnapshot() && now > inode.getAccessTime() + getAccessTimePrecision(); return new GetBlockLocationsResult(updateAccessTime, blocks);
static void assertSnapshot(INodesInPath inodesInPath, boolean isSnapshot, final Snapshot snapshot, int index) { assertEquals(isSnapshot, inodesInPath.isSnapshot()); assertEquals(Snapshot.getSnapshotId(isSnapshot ? snapshot : null), inodesInPath.getPathSnapshotId()); if (!isSnapshot) { assertEquals(Snapshot.getSnapshotId(snapshot), inodesInPath.getLatestSnapshotId()); } if (isSnapshot && index >= 0) { assertEquals(Snapshot.Root.class, inodesInPath.getINode(index).getClass()); } }