/** * Resolves the given path into inodes. Reserved paths are not handled and * permissions are not verified. Client supplied paths should be * resolved via {@link #resolvePath(FSPermissionChecker, String, DirOp)}. * This method should only be used by internal methods. * @return the {@link INodesInPath} containing all inodes in the path. * @throws UnresolvedLinkException * @throws ParentNotDirectoryException * @throws AccessControlException */ public INodesInPath getINodesInPath(String src, DirOp dirOp) throws UnresolvedLinkException, AccessControlException, ParentNotDirectoryException { return getINodesInPath(INode.getPathComponents(src), dirOp); }
static String resolvePath(String src, FSDirectory fsd) throws FileNotFoundException { byte[][] pathComponents = INode.getPathComponents(src); pathComponents = resolveComponents(pathComponents, fsd); return DFSUtil.byteArray2PathString(pathComponents); }
return parent.getPathComponents(); inode.getPathComponents(), pathComponents, 4);
INodesInPath resolvePath(FSPermissionChecker pc, String src, long fileId) throws UnresolvedLinkException, FileNotFoundException, AccessControlException, ParentNotDirectoryException { // Older clients may not have given us an inode ID to work with. // In this case, we have to try to resolve the path and hope it // hasn't changed or been deleted since the file was opened for write. INodesInPath iip; if (fileId == HdfsConstants.GRANDFATHER_INODE_ID) { iip = resolvePath(pc, src, DirOp.WRITE); } else { INode inode = getInode(fileId); if (inode == null) { iip = INodesInPath.fromComponents(INode.getPathComponents(src)); } else { iip = INodesInPath.fromINode(inode); } } return iip; }
byte[][] components = INode.getPathComponents(src); boolean isRaw = isReservedRawName(components); if (isPermissionEnabled && pc != null && isRaw) {
static DirectoryListing getListingInt(FSDirectory fsd, FSPermissionChecker pc, final String srcArg, byte[] startAfter, boolean needLocation) throws IOException { final INodesInPath iip = fsd.resolvePath(pc, srcArg, DirOp.READ); // Get file name when startAfter is an INodePath. This is not the // common case so avoid any unnecessary processing unless required. if (startAfter.length > 0 && startAfter[0] == Path.SEPARATOR_CHAR) { final String startAfterString = DFSUtil.bytes2String(startAfter); if (FSDirectory.isReservedName(startAfterString)) { try { byte[][] components = INode.getPathComponents(startAfterString); components = FSDirectory.resolveComponents(components, fsd); startAfter = components[components.length - 1]; } catch (IOException e) { // Possibly the inode is deleted throw new DirectoryListingStartAfterNotFoundException( "Can't find startAfter " + startAfterString); } } } boolean isSuperUser = true; if (fsd.isPermissionEnabled()) { if (iip.getLastINode() != null && iip.getLastINode().isDirectory()) { fsd.checkPathAccess(pc, iip, FsAction.READ_EXECUTE); } isSuperUser = pc.isSuperUser(); } return getListing(fsd, iip, startAfter, needLocation, isSuperUser); }
/** @return the {@link INodesInPath} containing all inodes in the path. */ public INodesInPath getINodesInPath(String path, boolean resolveLink) throws UnresolvedLinkException { final byte[][] components = INode.getPathComponents(path); return INodesInPath.resolve(rootDir, components, resolveLink); }
/** @return the {@link INodesInPath} containing all inodes in the path. */ public INodesInPath getINodesInPath(String path, boolean resolveLink) throws UnresolvedLinkException { final byte[][] components = INode.getPathComponents(path); return INodesInPath.resolve(rootDir, components, resolveLink); }
/** * Breaks file path into components. * @param path * @return array of byte arrays each of which represents * a single path component. */ static byte[][] getPathComponents(String path) { return getPathComponents(getPathNames(path)); }
static String resolvePath(String src, FSDirectory fsd) throws FileNotFoundException { byte[][] pathComponents = INode.getPathComponents(src); pathComponents = resolveComponents(pathComponents, fsd); return DFSUtil.byteArray2PathString(pathComponents); }
static String resolvePath(String src, FSDirectory fsd) throws FileNotFoundException { byte[][] pathComponents = INode.getPathComponents(src); pathComponents = resolveComponents(pathComponents, fsd); return DFSUtil.byteArray2PathString(pathComponents); }
/** */ INode unprotectedMkdir(String src, PermissionStatus permissions, long timestamp) throws QuotaExceededException { byte[][] components = INode.getPathComponents(src); INode[] inodes = new INode[components.length]; synchronized (rootDir) { rootDir.getExistingPathINodes(components, inodes); unprotectedMkdir(inodes, inodes.length-1, components[inodes.length-1], permissions, false, timestamp); return inodes[inodes.length-1]; } }
public void testString(String str) throws Exception { String pathString = str; byte[][] oldPathComponents = INode.getPathComponents(pathString); byte[][] newPathComponents = DFSUtil.bytes2byteArray(pathString.getBytes("UTF-8"), (byte) Path.SEPARATOR_CHAR); if (oldPathComponents[0] == null) { assertTrue(oldPathComponents[0] == newPathComponents[0]); } else { assertTrue("Path components do not match for " + pathString, Arrays.deepEquals(oldPathComponents, newPathComponents)); } } }
/** Add a node child to the namespace. The full path name of the node is src. * childDiskspace should be -1, if unknown. * QuotaExceededException is thrown if it violates quota limit */ private <T extends INode> T addNode(String src, T child, long childDiskspace, boolean inheritPermission) throws QuotaExceededException { byte[][] components = INode.getPathComponents(src); child.setLocalName(components[components.length-1]); INode[] inodes = new INode[components.length]; synchronized (rootDir) { rootDir.getExistingPathINodes(components, inodes); return addChild(inodes, inodes.length-1, child, childDiskspace, inheritPermission); } }
/** * @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; }
INodesInPath resolvePath(FSPermissionChecker pc, String src, boolean resolveLink) throws UnresolvedLinkException, FileNotFoundException, AccessControlException { byte[][] components = INode.getPathComponents(src); if (isPermissionEnabled && pc != null && isReservedRawName(components)) { pc.checkSuperuserPrivilege(); } components = resolveComponents(components, this); return INodesInPath.resolve(rootDir, components, resolveLink); }
INodesInPath resolvePath(FSPermissionChecker pc, String src, boolean resolveLink) throws UnresolvedLinkException, FileNotFoundException, AccessControlException { byte[][] components = INode.getPathComponents(src); if (isPermissionEnabled && pc != null && isReservedRawName(components)) { pc.checkSuperuserPrivilege(); } components = resolveComponents(components, this); return INodesInPath.resolve(rootDir, components, resolveLink); }
/** */ INode unprotectedMkdir(String src, PermissionStatus permissions, long timestamp) throws QuotaExceededException { byte[][] components = INode.getPathComponents(src); INode[] inodes = new INode[components.length]; writeLock(); try { rootDir.getExistingPathINodes(components, inodes); unprotectedMkdir(inodes, inodes.length-1, components[inodes.length-1], permissions, false, timestamp); return inodes[inodes.length-1]; } finally { writeUnlock(); } }
/** * Test for {@link FSDirectory#getPathComponents(INode)} */ @Test public void testGetPathFromInode() throws QuotaExceededException { String path = "/a/b/c"; INode inode = createTreeOfInodes(path); byte[][] expected = INode.getPathComponents(path); byte[][] actual = FSDirectory.getPathComponents(inode); DFSTestUtil.checkComponentsEquals(expected, actual); }