From 43bb7c8d529364af325be7fee7442997d807b11a Mon Sep 17 00:00:00 2001 From: Ivan Mitic Date: Wed, 25 Sep 2013 05:17:47 +0000 Subject: [PATCH] HADOOP-9776. HarFileSystem.listStatus() returns invalid authority if port number is empty. Contributed by Shanyu Zhao. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1526109 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../main/java/org/apache/hadoop/fs/HarFileSystem.java | 3 ++- .../org/apache/hadoop/fs/TestHarFileSystemBasics.java | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 3da6d1ebec..7604d4efc2 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -396,6 +396,9 @@ Release 2.1.2 - UNRELEASED BUG FIXES + HADOOP-9776. HarFileSystem.listStatus() returns invalid authority if port + number is empty. (Shanyu Zhao via ivanmi) + Release 2.1.1-beta - 2013-09-23 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/HarFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/HarFileSystem.java index 9c6f04749b..6f1dab0f8a 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/HarFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/HarFileSystem.java @@ -283,8 +283,9 @@ public Path getWorkingDirectory() { private String getHarAuth(URI underLyingUri) { String auth = underLyingUri.getScheme() + "-"; if (underLyingUri.getHost() != null) { - auth += underLyingUri.getHost() + ":"; + auth += underLyingUri.getHost(); if (underLyingUri.getPort() != -1) { + auth += ":"; auth += underLyingUri.getPort(); } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHarFileSystemBasics.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHarFileSystemBasics.java index b01cf47ddf..424257496e 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHarFileSystemBasics.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestHarFileSystemBasics.java @@ -221,6 +221,17 @@ public void testPositiveInitWithoutUnderlyingFS() throws Exception { hfs.initialize(uri, new Configuration()); } + @Test + public void testPositiveListFilesNotEndInColon() throws Exception { + // re-initialize the har file system with host name + // make sure the qualified path name does not append ":" at the end of host name + final URI uri = new URI("har://file-localhost" + harPath.toString()); + harFileSystem.initialize(uri, conf); + Path p1 = new Path("har://file-localhost" + harPath.toString()); + Path p2 = harFileSystem.makeQualified(p1); + assertTrue(p2.toUri().toString().startsWith("har://file-localhost/")); + } + // ========== Negative: @Test