HADOOP-7145. Configuration.getLocalPath should trim whitespace from the provided directories. Contributed by Todd Lipcon.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1071035 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e59ee1b4a8
commit
02f996d594
|
@ -493,6 +493,9 @@ Release 0.22.0 - Unreleased
|
||||||
|
|
||||||
HADOOP-7094. hadoop.css got lost during project split (cos)
|
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
|
Release 0.21.1 - Unreleased
|
||||||
|
|
||||||
IMPROVEMENTS
|
IMPROVEMENTS
|
||||||
|
|
|
@ -1248,7 +1248,7 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
||||||
*/
|
*/
|
||||||
public Path getLocalPath(String dirsProp, String path)
|
public Path getLocalPath(String dirsProp, String path)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
String[] dirs = getStrings(dirsProp);
|
String[] dirs = getTrimmedStrings(dirsProp);
|
||||||
int hashCode = path.hashCode();
|
int hashCode = path.hashCode();
|
||||||
FileSystem fs = FileSystem.getLocal(this);
|
FileSystem fs = FileSystem.getLocal(this);
|
||||||
for (int i = 0; i < dirs.length; i++) { // try each local dir
|
for (int i = 0; i < dirs.length; i++) { // try each local dir
|
||||||
|
@ -1280,7 +1280,7 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
||||||
*/
|
*/
|
||||||
public File getFile(String dirsProp, String path)
|
public File getFile(String dirsProp, String path)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
String[] dirs = getStrings(dirsProp);
|
String[] dirs = getTrimmedStrings(dirsProp);
|
||||||
int hashCode = path.hashCode();
|
int hashCode = path.hashCode();
|
||||||
for (int i = 0; i < dirs.length; i++) { // try each local dir
|
for (int i = 0; i < dirs.length; i++) { // try each local dir
|
||||||
int index = (hashCode+i & Integer.MAX_VALUE) % dirs.length;
|
int index = (hashCode+i & Integer.MAX_VALUE) % dirs.length;
|
||||||
|
|
|
@ -243,6 +243,30 @@ public class TestConfiguration extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
public void testToString() throws IOException {
|
||||||
out=new BufferedWriter(new FileWriter(CONFIG));
|
out=new BufferedWriter(new FileWriter(CONFIG));
|
||||||
startConfig();
|
startConfig();
|
||||||
|
|
Loading…
Reference in New Issue