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 om...@apache.org on 2011/03/04 05:36:49 UTC
svn commit: r1077616 - in
/hadoop/common/branches/branch-0.20-security-patches/src:
core/org/apache/hadoop/fs/FileSystem.java
mapred/org/apache/hadoop/mapred/JobHistory.java
Author: omalley
Date: Fri Mar 4 04:36:49 2011
New Revision: 1077616
URL: http://svn.apache.org/viewvc?rev=1077616&view=rev
Log:
commit e767ec4da9b8981c5955dbb159b1b54fd66cd3d6
Author: Arun C Murthy <ac...@apache.org>
Date: Wed Jul 28 18:47:15 2010 -0700
MAPREDUCE-323. Fix a NPE during listing directories for non-existing date buckets.
Modified:
hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/FileSystem.java
hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapred/JobHistory.java
Modified: hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/FileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/FileSystem.java?rev=1077616&r1=1077615&r2=1077616&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/FileSystem.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/FileSystem.java Fri Mar 4 04:36:49 2011
@@ -752,6 +752,7 @@ public abstract class FileSystem extends
* @param f
* given path
* @return the statuses of the files/directories in the given patch
+ * returns null, if Path f does not exist in the FileSystem
* @throws IOException
*/
public abstract FileStatus[] listStatus(Path f) throws IOException;
Modified: hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapred/JobHistory.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapred/JobHistory.java?rev=1077616&r1=1077615&r2=1077616&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapred/JobHistory.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/mapred/org/apache/hadoop/mapred/JobHistory.java Fri Mar 4 04:36:49 2011
@@ -918,65 +918,75 @@ public class JobHistory {
return localGlobber(fs, root, tail, filter, null);
}
+ private static FileStatus[] nullToEmpty(FileStatus[] result) {
+ return result == null ? new FileStatus[0] : result;
+ }
+
+ private static FileStatus[] listFilteredStatus
+ (FileSystem fs, Path root, PathFilter filter)
+ throws IOException {
+ return filter == null ? fs.listStatus(root) : fs.listStatus(root, filter);
+ }
// hasMismatches is just used to return a second value if you want
// one. I would have used MutableBoxedBoolean if such had been provided.
static FileStatus[] localGlobber
- (FileSystem fs, Path root, String tail, PathFilter filter, AtomicBoolean hasFlatFiles)
+ (FileSystem fs, Path root, String tail, PathFilter filter,
+ AtomicBoolean hasFlatFiles)
throws IOException {
if (tail.equals("")) {
- return filter == null ? fs.listStatus(root) : fs.listStatus(root, filter);
+ return nullToEmpty(listFilteredStatus(fs, root, filter));
}
- if (tail.startsWith("/*")) {
- Path[] subdirs = filteredStat2Paths(fs.listStatus(root), true, hasFlatFiles);
+ if (tail.startsWith("/*")) {
+ Path[] subdirs = filteredStat2Paths(nullToEmpty(fs.listStatus(root)),
+ true, hasFlatFiles);
- FileStatus[][] subsubdirs = new FileStatus[subdirs.length][];
+ FileStatus[][] subsubdirs = new FileStatus[subdirs.length][];
- int subsubdirCount = 0;
-
- if (subsubdirs.length == 0) {
- return new FileStatus[0];
- }
+ int subsubdirCount = 0;
- String newTail = tail.substring(2);
+ if (subsubdirs.length == 0) {
+ return new FileStatus[0];
+ }
- for (int i = 0; i < subdirs.length; ++i) {
- subsubdirs[i] = localGlobber(fs, subdirs[i], newTail, filter, null);
- subsubdirCount += subsubdirs[i].length;
- }
+ String newTail = tail.substring(2);
- FileStatus[] result = new FileStatus[subsubdirCount];
+ for (int i = 0; i < subdirs.length; ++i) {
+ subsubdirs[i] = localGlobber(fs, subdirs[i], newTail, filter, null);
+ subsubdirCount += subsubdirs[i].length;
+ }
- int segmentStart = 0;
+ FileStatus[] result = new FileStatus[subsubdirCount];
- for (int i = 0; i < subsubdirs.length; ++i) {
- System.arraycopy(subsubdirs[i], 0, result, segmentStart, subsubdirs[i].length);
- segmentStart += subsubdirs[i].length;
- }
+ int segmentStart = 0;
- return result;
+ for (int i = 0; i < subsubdirs.length; ++i) {
+ System.arraycopy(subsubdirs[i], 0, result, segmentStart, subsubdirs[i].length);
+ segmentStart += subsubdirs[i].length;
}
- if (tail.startsWith("/")) {
- int split = tail.indexOf('/', 1);
+ return result;
+ }
- if (split < 0) {
- return (filter == null
- ? fs.listStatus(new Path(root, tail.substring(1)))
- : fs.listStatus(new Path(root, tail.substring(1)), filter));
- } else {
- String thisSegment = tail.substring(1, split);
- String newTail = tail.substring(split);
- return localGlobber
- (fs, new Path(root, thisSegment), newTail, filter, hasFlatFiles);
- }
+ if (tail.startsWith("/")) {
+ int split = tail.indexOf('/', 1);
+
+ if (split < 0) {
+ return nullToEmpty
+ (listFilteredStatus(fs, new Path(root, tail.substring(1)), filter));
+ } else {
+ String thisSegment = tail.substring(1, split);
+ String newTail = tail.substring(split);
+ return localGlobber
+ (fs, new Path(root, thisSegment), newTail, filter, hasFlatFiles);
}
+ }
- IOException e = new IOException("localGlobber: bad tail");
+ IOException e = new IOException("localGlobber: bad tail");
- throw e;
- }
+ throw e;
+ }
static Path confPathFromLogFilePath(Path logFile) {
String jobId = jobIdNameFromLogFileName(logFile.getName());