Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2EBFC200C04 for ; Tue, 10 Jan 2017 03:01:45 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 2D590160B49; Tue, 10 Jan 2017 02:01:45 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 523EF160B3E for ; Tue, 10 Jan 2017 03:01:44 +0100 (CET) Received: (qmail 70094 invoked by uid 500); 10 Jan 2017 02:01:43 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 70085 invoked by uid 99); 10 Jan 2017 02:01:43 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Jan 2017 02:01:43 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 499E2DFA0E; Tue, 10 Jan 2017 02:01:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: wang@apache.org To: common-commits@hadoop.apache.org Message-Id: <4f4cb43762d542efb32e40fb1d5bd421@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HADOOP-13885. Implement getLinkTarget for ViewFileSystem. Contributed by Manoj Govindassamy. Date: Tue, 10 Jan 2017 02:01:43 +0000 (UTC) archived-at: Tue, 10 Jan 2017 02:01:45 -0000 Repository: hadoop Updated Branches: refs/heads/trunk 603cbcd51 -> 511d39e07 HADOOP-13885. Implement getLinkTarget for ViewFileSystem. Contributed by Manoj Govindassamy. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/511d39e0 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/511d39e0 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/511d39e0 Branch: refs/heads/trunk Commit: 511d39e0740f36bf937e7bcf974e1050f0e7c1e0 Parents: 603cbcd Author: Andrew Wang Authored: Mon Jan 9 18:01:10 2017 -0800 Committer: Andrew Wang Committed: Mon Jan 9 18:01:37 2017 -0800 ---------------------------------------------------------------------- .../hadoop/fs/viewfs/ChRootedFileSystem.java | 5 ++ .../apache/hadoop/fs/viewfs/ViewFileSystem.java | 11 +++ .../fs/viewfs/ViewFileSystemBaseTest.java | 73 ++++++++++++++++++++ 3 files changed, 89 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/511d39e0/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java index 272433f..fe2f8a9 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java @@ -234,6 +234,11 @@ class ChRootedFileSystem extends FilterFileSystem { } @Override + public Path getLinkTarget(Path f) throws IOException { + return super.getLinkTarget(fullPath(f)); + } + + @Override public void access(Path path, FsAction mode) throws AccessControlException, FileNotFoundException, IOException { super.access(fullPath(path), mode); http://git-wip-us.apache.org/repos/asf/hadoop/blob/511d39e0/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java index 8be666c..e16da64 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java @@ -876,6 +876,17 @@ public class ViewFileSystem extends FileSystem { } } + @Override + public Path getLinkTarget(Path path) throws IOException { + InodeTree.ResolveResult res; + try { + res = fsState.resolve(getUriPath(path), true); + } catch (FileNotFoundException e) { + throw new NotInMountpointException(path, "getLinkTarget"); + } + return res.targetFileSystem.getLinkTarget(res.remainingPath); + } + /** * An instance of this class represents an internal dir of the viewFs * that is internal dir of the mount table. http://git-wip-us.apache.org/repos/asf/hadoop/blob/511d39e0/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java index 9a0bf02..61295b4 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java @@ -51,6 +51,7 @@ import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.security.Credentials; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.token.Token; +import org.junit.Assume; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.apache.hadoop.fs.FileSystemTestHelper.*; @@ -1137,4 +1138,76 @@ abstract public class ViewFileSystemBaseTest { "the mounted FileSystem!", usedSpaceByPathViaTargetFs, usedSpaceByPathViaViewFs); } + + @Test + public void testLinkTarget() throws Exception { + + Assume.assumeTrue(fsTarget.supportsSymlinks() && + fsTarget.areSymlinksEnabled()); + + // Symbolic link + final String targetFileName = "debug.log"; + final String linkFileName = "debug.link"; + final Path targetFile = new Path(targetTestRoot, targetFileName); + final Path symLink = new Path(targetTestRoot, linkFileName); + + FileSystemTestHelper.createFile(fsTarget, targetFile); + fsTarget.createSymlink(targetFile, symLink, false); + + final Path mountTargetRootPath = new Path("/targetRoot"); + final Path mountTargetSymLinkPath = new Path(mountTargetRootPath, + linkFileName); + final Path expectedMountLinkTarget = fsTarget.makeQualified( + new Path(targetTestRoot, targetFileName)); + final Path actualMountLinkTarget = fsView.getLinkTarget( + mountTargetSymLinkPath); + + assertEquals("Resolved link target path not matching!", + expectedMountLinkTarget, actualMountLinkTarget); + + // Relative symbolic link + final String relativeFileName = "dir2/../" + targetFileName; + final String link2FileName = "dir2/rel.link"; + final Path relTargetFile = new Path(targetTestRoot, relativeFileName); + final Path relativeSymLink = new Path(targetTestRoot, link2FileName); + fsTarget.createSymlink(relTargetFile, relativeSymLink, true); + + final Path mountTargetRelativeSymLinkPath = new Path(mountTargetRootPath, + link2FileName); + final Path expectedMountRelLinkTarget = fsTarget.makeQualified( + new Path(targetTestRoot, relativeFileName)); + final Path actualMountRelLinkTarget = fsView.getLinkTarget( + mountTargetRelativeSymLinkPath); + + assertEquals("Resolved relative link target path not matching!", + expectedMountRelLinkTarget, actualMountRelLinkTarget); + + try { + fsView.getLinkTarget(new Path("/linkToAFile")); + fail("Resolving link target for a ViewFs mount link should fail!"); + } catch (Exception e) { + LOG.info("Expected exception: " + e); + assertThat(e.getMessage(), + containsString("not a symbolic link")); + } + + try { + fsView.getLinkTarget(fsView.makeQualified( + new Path(mountTargetRootPath, targetFileName))); + fail("Resolving link target for a non sym link should fail!"); + } catch (Exception e) { + LOG.info("Expected exception: " + e); + assertThat(e.getMessage(), + containsString("not a symbolic link")); + } + + try { + fsView.getLinkTarget(new Path("/targetRoot/non-existing-file")); + fail("Resolving link target for a non existing link should fail!"); + } catch (Exception e) { + LOG.info("Expected exception: " + e); + assertThat(e.getMessage(), + containsString("File does not exist:")); + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org