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:
parent
245c628819
commit
50688744ba
@ -204,6 +204,8 @@ Trunk (unreleased changes)
|
|||||||
|
|
||||||
HADOOP-1886. Undocumented parameters in FilesSystem. (Frank Conrad via eli)
|
HADOOP-1886. Undocumented parameters in FilesSystem. (Frank Conrad via eli)
|
||||||
|
|
||||||
|
HADOOP-7375. Add resolvePath method to FileContext. (Sanjay Radia via eli)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HADOOP-7333. Performance improvement in PureJavaCrc32. (Eric Caspole
|
HADOOP-7333. Performance improvement in PureJavaCrc32. (Eric Caspole
|
||||||
|
@ -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.
|
* Make the path fully qualified if it is isn't.
|
||||||
* A Fully-qualified path has scheme and authority specified and an absolute
|
* 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.
|
* Resolves all symbolic links in the specified path.
|
||||||
* Returns the new path object.
|
* Returns the new path object.
|
||||||
*/
|
*/
|
||||||
protected Path resolve(final Path f) throws IOException {
|
protected Path resolve(final Path f) throws FileNotFoundException,
|
||||||
return new FSLinkResolver<FileStatus>() {
|
UnresolvedLinkException, AccessControlException, IOException {
|
||||||
public FileStatus next(final AbstractFileSystem fs, final Path p)
|
return new FSLinkResolver<Path>() {
|
||||||
|
public Path next(final AbstractFileSystem fs, final Path p)
|
||||||
throws IOException, UnresolvedLinkException {
|
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)
|
Set<AbstractFileSystem> resolveAbstractFileSystems(final Path f)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final Path absF = fixRelativePart(f);
|
final Path absF = fixRelativePart(f);
|
||||||
final HashSet<AbstractFileSystem> result = new HashSet<AbstractFileSystem>();
|
final HashSet<AbstractFileSystem> result
|
||||||
|
= new HashSet<AbstractFileSystem>();
|
||||||
new FSLinkResolver<Void>() {
|
new FSLinkResolver<Void>() {
|
||||||
public Void next(final AbstractFileSystem fs, final Path p)
|
public Void next(final AbstractFileSystem fs, final Path p)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
|
@ -468,20 +468,20 @@ public void testgetLinkTargetOnNonLink() throws IOException {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResolvePathInternalPaths() throws IOException {
|
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"),
|
Assert.assertEquals(new Path("/internalDir"),
|
||||||
fcView.getDefaultFileSystem().resolvePath(new Path("/internalDir")));
|
fcView.resolvePath(new Path("/internalDir")));
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testResolvePathMountPoints() throws IOException {
|
public void testResolvePathMountPoints() throws IOException {
|
||||||
Assert.assertEquals(new Path(targetTestRoot,"user"),
|
Assert.assertEquals(new Path(targetTestRoot,"user"),
|
||||||
fcView.getDefaultFileSystem().resolvePath(new Path("/user")));
|
fcView.resolvePath(new Path("/user")));
|
||||||
Assert.assertEquals(new Path(targetTestRoot,"data"),
|
Assert.assertEquals(new Path(targetTestRoot,"data"),
|
||||||
fcView.getDefaultFileSystem().resolvePath(new Path("/data")));
|
fcView.resolvePath(new Path("/data")));
|
||||||
Assert.assertEquals(new Path(targetTestRoot,"dir2"),
|
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"),
|
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 {
|
public void testResolvePathThroughMountPoints() throws IOException {
|
||||||
FileContextTestHelper.createFile(fcView, "/user/foo");
|
FileContextTestHelper.createFile(fcView, "/user/foo");
|
||||||
Assert.assertEquals(new Path(targetTestRoot,"user/foo"),
|
Assert.assertEquals(new Path(targetTestRoot,"user/foo"),
|
||||||
fcView.getDefaultFileSystem().resolvePath(new Path("/user/foo")));
|
fcView.resolvePath(new Path("/user/foo")));
|
||||||
|
|
||||||
fcView.mkdir(
|
fcView.mkdir(
|
||||||
FileContextTestHelper.getTestRootPath(fcView, "/user/dirX"),
|
FileContextTestHelper.getTestRootPath(fcView, "/user/dirX"),
|
||||||
FileContext.DEFAULT_PERM, false);
|
FileContext.DEFAULT_PERM, false);
|
||||||
Assert.assertEquals(new Path(targetTestRoot,"user/dirX"),
|
Assert.assertEquals(new Path(targetTestRoot,"user/dirX"),
|
||||||
fcView.getDefaultFileSystem().resolvePath(new Path("/user/dirX")));
|
fcView.resolvePath(new Path("/user/dirX")));
|
||||||
|
|
||||||
|
|
||||||
fcView.mkdir(
|
fcView.mkdir(
|
||||||
FileContextTestHelper.getTestRootPath(fcView, "/user/dirX/dirY"),
|
FileContextTestHelper.getTestRootPath(fcView, "/user/dirX/dirY"),
|
||||||
FileContext.DEFAULT_PERM, false);
|
FileContext.DEFAULT_PERM, false);
|
||||||
Assert.assertEquals(new Path(targetTestRoot,"user/dirX/dirY"),
|
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)
|
@Test(expected=FileNotFoundException.class)
|
||||||
public void testResolvePathDanglingLink() throws IOException {
|
public void testResolvePathDanglingLink() throws IOException {
|
||||||
fcView.getDefaultFileSystem().resolvePath(new Path("/danglingLink"));
|
fcView.resolvePath(new Path("/danglingLink"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=FileNotFoundException.class)
|
@Test(expected=FileNotFoundException.class)
|
||||||
public void testResolvePathMissingThroughMountPoints() throws IOException {
|
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(
|
fcView.mkdir(
|
||||||
FileContextTestHelper.getTestRootPath(fcView, "/user/dirX"),
|
FileContextTestHelper.getTestRootPath(fcView, "/user/dirX"),
|
||||||
FileContext.DEFAULT_PERM, false);
|
FileContext.DEFAULT_PERM, false);
|
||||||
fcView.getDefaultFileSystem().resolvePath(new Path("/user/dirX/nonExisting"));
|
fcView.resolvePath(new Path("/user/dirX/nonExisting"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user