HDFS-4784. Merge r1478276 from trunk

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1478287 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Suresh Srinivas 2013-05-02 06:56:19 +00:00
parent ab8ce0fcda
commit bd198d7dfe
3 changed files with 23 additions and 6 deletions

View File

@ -227,6 +227,8 @@ Release 2.0.5-beta - UNRELEASED
HDFS-4785. Concat operation does not remove concatenated files from
InodeMap. (suresh)
HDFS-4784. NPE in FSDirectory.resolvePath(). (Brandon Li via suresh)
Release 2.0.4-alpha - UNRELEASED
INCOMPATIBLE CHANGES

View File

@ -1090,7 +1090,7 @@ public class FSDirectory implements Closeable {
NameNode.stateChangeLog.debug("DIR* FSDirectory.unprotectedDelete: "
+src+" is removed");
}
remvoedAllFromInodesFromMap(targetNode);
removeAllFromInodesFromMap(targetNode);
return filesRemoved;
}
@ -1783,14 +1783,14 @@ public class FSDirectory implements Closeable {
}
/** 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();
}
@ -2253,14 +2253,18 @@ public class FSDirectory implements Closeable {
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]));
}

View File

@ -901,5 +901,16 @@ public class TestINodeFile {
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);
}
}
}