From a3c4488efd3556cb9a14a520e2c06a9fa022ec29 Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Thu, 7 Mar 2013 21:32:12 +0000 Subject: [PATCH] HADOOP-9364. PathData#expandAsGlob does not return correct results for absolute paths on Windows. Contributed by Ivan Mitic. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1454108 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 +++ .../org/apache/hadoop/fs/shell/PathData.java | 3 ++- .../apache/hadoop/fs/shell/TestPathData.java | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index b2fd8d3c9a9..7e0e6a5617e 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -461,6 +461,9 @@ Trunk (Unreleased) HADOOP-9365. TestHAZKUtil fails on Windows. (Ivan Mitic via suresh) + HADOOP-9364. PathData#expandAsGlob does not return correct results for + absolute paths on Windows. (Ivan Mitic via suresh) + Release 2.0.5-beta - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java index ae719f5796d..88a90c6e6ff 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java @@ -338,7 +338,8 @@ public class PathData implements Comparable { URI globUri = globPath.toUri(); if (globUri.getScheme() != null) { globType = PathType.HAS_SCHEME; - } else if (new File(globUri.getPath()).isAbsolute()) { + } else if (!globUri.getPath().isEmpty() && + new Path(globUri.getPath()).isAbsolute()) { globType = PathType.SCHEMELESS_ABSOLUTE; } else { globType = PathType.RELATIVE; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestPathData.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestPathData.java index 320a79eccaa..3ddd68da23f 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestPathData.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestPathData.java @@ -23,11 +23,13 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; +import java.net.URI; import java.util.Arrays; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.util.Shell; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -173,6 +175,25 @@ public class TestPathData { sortedString(testDir+"/d1/f1", testDir+"/d1/f1.1"), sortedString(items) ); + + String absolutePathNoDriveLetter = testDir+"/d1/f1"; + if (Shell.WINDOWS) { + // testDir is an absolute path with a drive letter on Windows, i.e. + // c:/some/path + // and for the test we want something like the following + // /some/path + absolutePathNoDriveLetter = absolutePathNoDriveLetter.substring(2); + } + items = PathData.expandAsGlob(absolutePathNoDriveLetter, conf); + assertEquals( + sortedString(absolutePathNoDriveLetter), + sortedString(items) + ); + items = PathData.expandAsGlob(".", conf); + assertEquals( + sortedString("."), + sortedString(items) + ); } @Test (timeout = 30000)