You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by to...@apache.org on 2011/02/15 21:19:18 UTC

svn commit: r1071034 - in /hadoop/common/branches/branch-0.22: CHANGES.txt src/java/org/apache/hadoop/conf/Configuration.java src/test/core/org/apache/hadoop/conf/TestConfiguration.java

Author: todd
Date: Tue Feb 15 20:19:17 2011
New Revision: 1071034

URL: http://svn.apache.org/viewvc?rev=1071034&view=rev
Log:
HADOOP-7145. Configuration.getLocalPath should trim whitespace from the provided directories. Contributed by Todd Lipcon.

Modified:
    hadoop/common/branches/branch-0.22/CHANGES.txt
    hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java
    hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java

Modified: hadoop/common/branches/branch-0.22/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/CHANGES.txt?rev=1071034&r1=1071033&r2=1071034&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.22/CHANGES.txt Tue Feb 15 20:19:17 2011
@@ -420,6 +420,9 @@ Release 0.22.0 - Unreleased
 
     HADOOP-7094. hadoop.css got lost during project split (cos)
 
+    HADOOP-7145. Configuration.getLocalPath should trim whitespace from
+    the provided directories. (todd)
+
 Release 0.21.1 - Unreleased
 
   IMPROVEMENTS

Modified: hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java?rev=1071034&r1=1071033&r2=1071034&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java (original)
+++ hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java Tue Feb 15 20:19:17 2011
@@ -1238,7 +1238,7 @@ public class Configuration implements It
    */
   public Path getLocalPath(String dirsProp, String path)
     throws IOException {
-    String[] dirs = getStrings(dirsProp);
+    String[] dirs = getTrimmedStrings(dirsProp);
     int hashCode = path.hashCode();
     FileSystem fs = FileSystem.getLocal(this);
     for (int i = 0; i < dirs.length; i++) {  // try each local dir
@@ -1270,7 +1270,7 @@ public class Configuration implements It
    */
   public File getFile(String dirsProp, String path)
     throws IOException {
-    String[] dirs = getStrings(dirsProp);
+    String[] dirs = getTrimmedStrings(dirsProp);
     int hashCode = path.hashCode();
     for (int i = 0; i < dirs.length; i++) {  // try each local dir
       int index = (hashCode+i & Integer.MAX_VALUE) % dirs.length;

Modified: hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java?rev=1071034&r1=1071033&r2=1071034&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java (original)
+++ hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java Tue Feb 15 20:19:17 2011
@@ -243,6 +243,30 @@ public class TestConfiguration extends T
     }
   }
 
+  public void testGetLocalPath() throws IOException {
+    Configuration conf = new Configuration();
+    conf.set("dirs", "a, b, c ");
+    for (int i = 0; i < 1000; i++) {
+      String localPath = conf.getLocalPath("dirs", "dir" + i).toString();
+      assertTrue("Path doesn't end in specified dir: " + localPath,
+        localPath.endsWith("dir" + i));
+      assertFalse("Path has internal whitespace: " + localPath,
+        localPath.contains(" "));
+    }
+  }
+  
+  public void testGetFile() throws IOException {
+    Configuration conf = new Configuration();
+    conf.set("dirs", "a, b, c ");
+    for (int i = 0; i < 1000; i++) {
+      String localPath = conf.getFile("dirs", "dir" + i).toString();
+      assertTrue("Path doesn't end in specified dir: " + localPath,
+        localPath.endsWith("dir" + i));
+      assertFalse("Path has internal whitespace: " + localPath,
+        localPath.contains(" "));
+    }
+  }
+
   public void testToString() throws IOException {
     out=new BufferedWriter(new FileWriter(CONFIG));
     startConfig();