Przeglądaj źródła

HADOOP-1020. Fix a bug in Path resolution, and with unit tests on Windows.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@513049 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 lat temu
rodzic
commit
5477c8ea7c

+ 3 - 0
CHANGES.txt

@@ -165,6 +165,9 @@ Trunk (unreleased changes)
 49. HADOOP-940.  Improve HDFS's replication scheduling.
 49. HADOOP-940.  Improve HDFS's replication scheduling.
     (Dhruba Borthakur via cutting) 
     (Dhruba Borthakur via cutting) 
 
 
+50. HADOOP-1020.  Fix a bug in Path resolution, and a with unit tests
+    on Windows.  (cutting)
+
 
 
 Release 0.11.2 - 2007-02-16
 Release 0.11.2 - 2007-02-16
 
 

+ 1 - 0
src/contrib/build-contrib.xml

@@ -140,6 +140,7 @@
       
       
       <sysproperty key="test.build.data" value="${build.test}/data"/>
       <sysproperty key="test.build.data" value="${build.test}/data"/>
       <sysproperty key="build.test" value="${build.test}"/>
       <sysproperty key="build.test" value="${build.test}"/>
+      <sysproperty key="contrib.name" value="${name}"/>
       
       
       <!-- requires fork=yes for: 
       <!-- requires fork=yes for: 
         relative File paths to use the specified user.dir 
         relative File paths to use the specified user.dir 

+ 5 - 0
src/contrib/test/hadoop-site.xml

@@ -14,5 +14,10 @@
   <description>A base for other temporary directories.</description>
   <description>A base for other temporary directories.</description>
 </property>
 </property>
 
 
+<property>
+  <name>mapred.system.dir</name>
+  <value>build/contrib/${contrib.name}/test/system</value>
+</property>
+
 
 
 </configuration>
 </configuration>

+ 13 - 17
src/java/org/apache/hadoop/fs/Path.java

@@ -56,23 +56,19 @@ public class Path implements Comparable {
 
 
   /** Resolve a child path against a parent path. */
   /** Resolve a child path against a parent path. */
   public Path(Path parent, Path child) {
   public Path(Path parent, Path child) {
-    if (child.isAbsolute()) {
-      this.uri = child.uri;
-    } else {
-      // Add a slash to parent's path so resolution is compatible with URI's
-      URI parentUri = parent.uri;
-      String parentPath = parentUri.getPath();
-      if (!(parentPath.equals("/") || parentPath.equals("")))
-        try {
-          parentUri = new URI(parentUri.getScheme(), parentUri.getAuthority(),
-                              parentUri.getPath()+"/", null, null);
-        } catch (URISyntaxException e) {
-          throw new IllegalArgumentException(e);
-        }
-      URI resolved = parentUri.resolve(child.uri);
-      initialize(resolved.getScheme(), resolved.getAuthority(),
-                 normalizePath(resolved.getPath()));
-    }
+    // Add a slash to parent's path so resolution is compatible with URI's
+    URI parentUri = parent.uri;
+    String parentPath = parentUri.getPath();
+    if (!(parentPath.equals("/") || parentPath.equals("")))
+      try {
+        parentUri = new URI(parentUri.getScheme(), parentUri.getAuthority(),
+                            parentUri.getPath()+"/", null, null);
+      } catch (URISyntaxException e) {
+        throw new IllegalArgumentException(e);
+      }
+    URI resolved = parentUri.resolve(child.uri);
+    initialize(resolved.getScheme(), resolved.getAuthority(),
+               normalizePath(resolved.getPath()));
   }
   }
 
 
   /** Construct a path from a String.  Path strings are URIs, but with
   /** Construct a path from a String.  Path strings are URIs, but with

+ 6 - 0
src/test/org/apache/hadoop/fs/TestPath.java

@@ -136,4 +136,10 @@ public class TestPath extends TestCase {
     assertEquals(new Path("foo/bar/baz","../../../../..").toString(), "../..");
     assertEquals(new Path("foo/bar/baz","../../../../..").toString(), "../..");
   }
   }
   
   
+  public void testScheme() throws java.io.IOException {
+    assertEquals("foo:/bar", new Path("foo:/","/bar").toString()); 
+    assertEquals("foo://bar/baz", new Path("foo://bar/","/baz").toString()); 
+  }
+
+
 }
 }