HADOOP-7375. Add resolvePath method to FileContext. Contributed by Sanjay Radia

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1134854 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eli Collins 2011-06-12 01:36:13 +00:00
parent 245c628819
commit 50688744ba
3 changed files with 45 additions and 18 deletions

View File

@ -204,6 +204,8 @@ Trunk (unreleased changes)
HADOOP-1886. Undocumented parameters in FilesSystem. (Frank Conrad via eli)
HADOOP-7375. Add resolvePath method to FileContext. (Sanjay Radia via eli)
OPTIMIZATIONS
HADOOP-7333. Performance improvement in PureJavaCrc32. (Eric Caspole

View File

@ -546,6 +546,29 @@ public void setUMask(final FsPermission newUmask) {
}
/**
* Resolve the path following any symlinks or mount points
* @param f to be resolved
* @return fully qualified resolved path
*
* @throws FileNotFoundException If <code>f</code> does not exist
* @throws AccessControlException if access denied
* @throws IOException If an IO Error occurred
*
* Exceptions applicable to file systems accessed over RPC:
* @throws RpcClientException If an exception occurred in the RPC client
* @throws RpcServerException If an exception occurred in the RPC server
* @throws UnexpectedServerException If server implementation throws
* undeclared exception to RPC server
*
* RuntimeExceptions:
* @throws InvalidPathException If path <code>f</code> is not valid
*/
public Path resolvePath(final Path f) throws FileNotFoundException,
UnresolvedLinkException, AccessControlException, IOException {
return resolve(f);
}
/**
* Make the path fully qualified if it is isn't.
* A Fully-qualified path has scheme and authority specified and an absolute
@ -2204,13 +2227,14 @@ public synchronized void run() {
* Resolves all symbolic links in the specified path.
* Returns the new path object.
*/
protected Path resolve(final Path f) throws IOException {
return new FSLinkResolver<FileStatus>() {
public FileStatus next(final AbstractFileSystem fs, final Path p)
protected Path resolve(final Path f) throws FileNotFoundException,
UnresolvedLinkException, AccessControlException, IOException {
return new FSLinkResolver<Path>() {
public Path next(final AbstractFileSystem fs, final Path p)
throws IOException, UnresolvedLinkException {
return fs.getFileStatus(p);
return fs.resolvePath(p);
}
}.resolve(this, f).getPath();
}.resolve(this, f);
}
/**
@ -2240,7 +2264,8 @@ public FileStatus next(final AbstractFileSystem fs, final Path p)
Set<AbstractFileSystem> resolveAbstractFileSystems(final Path f)
throws IOException {
final Path absF = fixRelativePart(f);
final HashSet<AbstractFileSystem> result = new HashSet<AbstractFileSystem>();
final HashSet<AbstractFileSystem> result
= new HashSet<AbstractFileSystem>();
new FSLinkResolver<Void>() {
public Void next(final AbstractFileSystem fs, final Path p)
throws IOException, UnresolvedLinkException {

View File

@ -468,20 +468,20 @@ public void testgetLinkTargetOnNonLink() throws IOException {
@Test
public void testResolvePathInternalPaths() throws IOException {
Assert.assertEquals(new Path("/"), fcView.getDefaultFileSystem().resolvePath(new Path("/")));
Assert.assertEquals(new Path("/"), fcView.resolvePath(new Path("/")));
Assert.assertEquals(new Path("/internalDir"),
fcView.getDefaultFileSystem().resolvePath(new Path("/internalDir")));
fcView.resolvePath(new Path("/internalDir")));
}
@Test
public void testResolvePathMountPoints() throws IOException {
Assert.assertEquals(new Path(targetTestRoot,"user"),
fcView.getDefaultFileSystem().resolvePath(new Path("/user")));
fcView.resolvePath(new Path("/user")));
Assert.assertEquals(new Path(targetTestRoot,"data"),
fcView.getDefaultFileSystem().resolvePath(new Path("/data")));
fcView.resolvePath(new Path("/data")));
Assert.assertEquals(new Path(targetTestRoot,"dir2"),
fcView.getDefaultFileSystem().resolvePath(new Path("/internalDir/linkToDir2")));
fcView.resolvePath(new Path("/internalDir/linkToDir2")));
Assert.assertEquals(new Path(targetTestRoot,"dir3"),
fcView.getDefaultFileSystem().resolvePath(new Path("/internalDir/internalDir2/linkToDir3")));
fcView.resolvePath(new Path("/internalDir/internalDir2/linkToDir3")));
}
@ -489,30 +489,30 @@ public void testResolvePathMountPoints() throws IOException {
public void testResolvePathThroughMountPoints() throws IOException {
FileContextTestHelper.createFile(fcView, "/user/foo");
Assert.assertEquals(new Path(targetTestRoot,"user/foo"),
fcView.getDefaultFileSystem().resolvePath(new Path("/user/foo")));
fcView.resolvePath(new Path("/user/foo")));
fcView.mkdir(
FileContextTestHelper.getTestRootPath(fcView, "/user/dirX"),
FileContext.DEFAULT_PERM, false);
Assert.assertEquals(new Path(targetTestRoot,"user/dirX"),
fcView.getDefaultFileSystem().resolvePath(new Path("/user/dirX")));
fcView.resolvePath(new Path("/user/dirX")));
fcView.mkdir(
FileContextTestHelper.getTestRootPath(fcView, "/user/dirX/dirY"),
FileContext.DEFAULT_PERM, false);
Assert.assertEquals(new Path(targetTestRoot,"user/dirX/dirY"),
fcView.getDefaultFileSystem().resolvePath(new Path("/user/dirX/dirY")));
fcView.resolvePath(new Path("/user/dirX/dirY")));
}
@Test(expected=FileNotFoundException.class)
public void testResolvePathDanglingLink() throws IOException {
fcView.getDefaultFileSystem().resolvePath(new Path("/danglingLink"));
fcView.resolvePath(new Path("/danglingLink"));
}
@Test(expected=FileNotFoundException.class)
public void testResolvePathMissingThroughMountPoints() throws IOException {
fcView.getDefaultFileSystem().resolvePath(new Path("/user/nonExisting"));
fcView.resolvePath(new Path("/user/nonExisting"));
}
@ -521,7 +521,7 @@ public void testResolvePathMissingThroughMountPoints2() throws IOException {
fcView.mkdir(
FileContextTestHelper.getTestRootPath(fcView, "/user/dirX"),
FileContext.DEFAULT_PERM, false);
fcView.getDefaultFileSystem().resolvePath(new Path("/user/dirX/nonExisting"));
fcView.resolvePath(new Path("/user/dirX/nonExisting"));
}