HDFS-4784. NPE in FSDirectory.resolvePath(). Contributed by Brandon Li.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1478276 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
03ba436d42
commit
a4bae51b7d
@ -273,6 +273,8 @@ Trunk (Unreleased)
|
||||
HDFS-4785. Concat operation does not remove concatenated files from
|
||||
InodeMap. (suresh)
|
||||
|
||||
HDFS-4784. NPE in FSDirectory.resolvePath(). (Brandon Li via suresh)
|
||||
|
||||
BREAKDOWN OF HADOOP-8562 and HDFS-3602 SUBTASKS AND RELATED JIRAS
|
||||
|
||||
HDFS-4145. Merge hdfs cmd line scripts from branch-1-win. (David Lao,
|
||||
|
@ -1090,7 +1090,7 @@ int unprotectedDelete(String src, BlocksMapUpdateInfo collectedBlocks,
|
||||
NameNode.stateChangeLog.debug("DIR* FSDirectory.unprotectedDelete: "
|
||||
+src+" is removed");
|
||||
}
|
||||
remvoedAllFromInodesFromMap(targetNode);
|
||||
removeAllFromInodesFromMap(targetNode);
|
||||
return filesRemoved;
|
||||
}
|
||||
|
||||
@ -1783,14 +1783,14 @@ private final void removeFromInodeMap(INode inode) {
|
||||
}
|
||||
|
||||
/** Remove all the inodes under given inode from the map */
|
||||
private void remvoedAllFromInodesFromMap(INode inode) {
|
||||
private void removeAllFromInodesFromMap(INode inode) {
|
||||
removeFromInodeMap(inode);
|
||||
if (!inode.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
INodeDirectory dir = (INodeDirectory) inode;
|
||||
for (INode child : dir.getChildrenList()) {
|
||||
remvoedAllFromInodesFromMap(child);
|
||||
removeAllFromInodesFromMap(child);
|
||||
}
|
||||
dir.clearChildren();
|
||||
}
|
||||
@ -2258,14 +2258,18 @@ static String resolvePath(String src, byte[][] pathComponents, FSDirectory fsd)
|
||||
try {
|
||||
id = Long.valueOf(inodeId);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new FileNotFoundException(
|
||||
"File for given inode path does not exist: " + src);
|
||||
throw new FileNotFoundException("Invalid inode path: " + src);
|
||||
}
|
||||
if (id == INodeId.ROOT_INODE_ID && pathComponents.length == 4) {
|
||||
return Path.SEPARATOR;
|
||||
}
|
||||
INode inode = fsd.getInode(id);
|
||||
if (inode == null) {
|
||||
throw new FileNotFoundException(
|
||||
"File for given inode path does not exist: " + src);
|
||||
}
|
||||
StringBuilder path = id == INodeId.ROOT_INODE_ID ? new StringBuilder()
|
||||
: new StringBuilder(fsd.getInode(id).getFullPathName());
|
||||
: new StringBuilder(inode.getFullPathName());
|
||||
for (int i = 4; i < pathComponents.length; i++) {
|
||||
path.append(Path.SEPARATOR).append(DFSUtil.bytes2String(pathComponents[i]));
|
||||
}
|
||||
|
@ -909,6 +909,17 @@ public void testInodePath() throws FileNotFoundException {
|
||||
components = INode.getPathComponents(testPath);
|
||||
resolvedPath = FSDirectory.resolvePath(testPath, components, fsd);
|
||||
assertEquals(testPath, resolvedPath);
|
||||
|
||||
// Test path with nonexistent(deleted or wrong id) inode
|
||||
Mockito.doReturn(null).when(fsd).getInode(Mockito.anyLong());
|
||||
testPath = "/.reserved/.inodes/1234";
|
||||
components = INode.getPathComponents(testPath);
|
||||
try {
|
||||
String realPath = FSDirectory.resolvePath(testPath, components, fsd);
|
||||
fail("Path should not be resolved:" + realPath);
|
||||
} catch (IOException e) {
|
||||
assertTrue(e instanceof FileNotFoundException);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user