Browse Source

HADOOP-3157. Fix path handling in DistributedCache and TestMiniMRLocalFS. (Doug Cutting via rangadi)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@644994 13f79535-47bb-0310-9956-ffa450edef68
Raghu Angadi 17 years ago
parent
commit
e6aec74214

+ 3 - 0
CHANGES.txt

@@ -517,6 +517,9 @@ Trunk (unreleased changes)
     HADOOP-1911. Fix an infinite loop in DFSClient when all replicas of a
     block are bad (cdouglas)
 
+    HADOOP-3157. Fix path handling in DistributedCache and TestMiniMRLocalFS.
+    (Doug Cutting via rangadi) 
+
 Release 0.16.3 - Unreleased
 
   BUG FIXES

+ 12 - 8
src/java/org/apache/hadoop/filecache/DistributedCache.java

@@ -257,15 +257,19 @@ public class DistributedCache {
    */
   public static String makeRelative(URI cache, Configuration conf)
     throws IOException {
-    String fsname = cache.getScheme();
-    String path;
-    FileSystem dfs = FileSystem.get(conf);
-    if ("hdfs".equals(fsname)) {
-      path = cache.getHost() + cache.getPath();
-    } else {
-      String[] split = dfs.getName().split(":");
-      path = split[0] + cache.getPath();
+    String host = cache.getHost();
+    if (host == null) {
+      host = cache.getScheme();
+    }
+    if (host == null) {
+      URI defaultUri = FileSystem.get(conf).getUri();
+      host = defaultUri.getHost();
+      if (host == null) {
+        host = defaultUri.getScheme();
+      }
     }
+    String path = host + cache.getPath();
+    path = path.replace(":/","/");                // remove windows device colon
     return path;
   }
 

+ 1 - 1
src/test/org/apache/hadoop/mapred/TestMiniMRLocalFS.java

@@ -41,7 +41,7 @@ public class TestMiniMRLocalFS extends TestCase {
   static final int NUM_SAMPLES = 100000;
   private static String TEST_ROOT_DIR =
     new File(System.getProperty("test.build.data","/tmp"))
-    .toString().replace(' ', '+');
+    .toURI().toString().replace(' ', '+');
     
   public void testWithLocal() throws IOException {
     MiniMRCluster mr = null;