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 wh...@apache.org on 2015/07/17 00:22:14 UTC
hadoop git commit: HDFS-8767. RawLocalFileSystem.listStatus() returns
null for UNIX pipefile. Contributed by kanaka kumar avvaru.
Repository: hadoop
Updated Branches:
refs/heads/branch-2 516bbf1c2 -> 391d2d88f
HDFS-8767. RawLocalFileSystem.listStatus() returns null for UNIX pipefile. Contributed by kanaka kumar avvaru.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/391d2d88
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/391d2d88
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/391d2d88
Branch: refs/heads/branch-2
Commit: 391d2d88f2ace4e95e82f4303644ba9d1dd0692a
Parents: 516bbf1
Author: Haohui Mai <wh...@apache.org>
Authored: Thu Jul 16 15:21:53 2015 -0700
Committer: Haohui Mai <wh...@apache.org>
Committed: Thu Jul 16 15:22:11 2015 -0700
----------------------------------------------------------------------
hadoop-common-project/hadoop-common/CHANGES.txt | 3 ++
.../apache/hadoop/fs/RawLocalFileSystem.java | 53 +++++++++++---------
.../apache/hadoop/fs/TestLocalFileSystem.java | 22 ++++++++
3 files changed, 53 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/391d2d88/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index 370bd7f..1fde48e 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -501,6 +501,9 @@ Release 2.7.2 - UNRELEASED
HADOOP-12191. Bzip2Factory is not thread safe. (Brahma Reddy Battula
via ozawa)
+ HDFS-8767. RawLocalFileSystem.listStatus() returns null for UNIX pipefile.
+ (kanaka kumar avvaru via wheat9)
+
Release 2.7.1 - 2015-07-06
INCOMPATIBLE CHANGES
http://git-wip-us.apache.org/repos/asf/hadoop/blob/391d2d88/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
index 99a0b04..54fc6bb 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
@@ -446,35 +446,38 @@ public class RawLocalFileSystem extends FileSystem {
if (!localf.exists()) {
throw new FileNotFoundException("File " + f + " does not exist");
}
- if (localf.isFile()) {
- if (!useDeprecatedFileStatus) {
- return new FileStatus[] { getFileStatus(f) };
- }
- return new FileStatus[] {
- new DeprecatedRawLocalFileStatus(localf, getDefaultBlockSize(f), this)};
- }
- String[] names = localf.list();
- if (names == null) {
- return null;
- }
- results = new FileStatus[names.length];
- int j = 0;
- for (int i = 0; i < names.length; i++) {
- try {
- // Assemble the path using the Path 3 arg constructor to make sure
- // paths with colon are properly resolved on Linux
- results[j] = getFileStatus(new Path(f, new Path(null, null, names[i])));
- j++;
- } catch (FileNotFoundException e) {
- // ignore the files not found since the dir list may have have changed
- // since the names[] list was generated.
+ if (localf.isDirectory()) {
+ String[] names = localf.list();
+ if (names == null) {
+ return null;
+ }
+ results = new FileStatus[names.length];
+ int j = 0;
+ for (int i = 0; i < names.length; i++) {
+ try {
+ // Assemble the path using the Path 3 arg constructor to make sure
+ // paths with colon are properly resolved on Linux
+ results[j] = getFileStatus(new Path(f, new Path(null, null,
+ names[i])));
+ j++;
+ } catch (FileNotFoundException e) {
+ // ignore the files not found since the dir list may have have
+ // changed since the names[] list was generated.
+ }
+ }
+ if (j == names.length) {
+ return results;
}
+ return Arrays.copyOf(results, j);
}
- if (j == names.length) {
- return results;
+
+ if (!useDeprecatedFileStatus) {
+ return new FileStatus[] { getFileStatus(f) };
}
- return Arrays.copyOf(results, j);
+ return new FileStatus[] {
+ new DeprecatedRawLocalFileStatus(localf,
+ getDefaultBlockSize(f), this) };
}
protected boolean mkOneDir(File p2f) throws IOException {
http://git-wip-us.apache.org/repos/asf/hadoop/blob/391d2d88/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java
index e5d08a5..93e8c85 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java
@@ -31,11 +31,14 @@ import java.util.Random;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;
+import static org.mockito.Mockito.*;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.internal.util.reflection.Whitebox;
+
/**
* This class tests the local file system via the FileSystem abstraction.
@@ -607,4 +610,23 @@ public class TestLocalFileSystem {
}
}
+ @Test
+ public void testFileStatusPipeFile() throws Exception {
+ RawLocalFileSystem origFs = new RawLocalFileSystem();
+ RawLocalFileSystem fs = spy(origFs);
+ Configuration conf = mock(Configuration.class);
+ fs.setConf(conf);
+ Whitebox.setInternalState(fs, "useDeprecatedFileStatus", false);
+ Path path = new Path("/foo");
+ File pipe = mock(File.class);
+ when(pipe.isFile()).thenReturn(false);
+ when(pipe.isDirectory()).thenReturn(false);
+ when(pipe.exists()).thenReturn(true);
+
+ FileStatus stat = mock(FileStatus.class);
+ doReturn(pipe).when(fs).pathToFile(path);
+ doReturn(stat).when(fs).getFileStatus(path);
+ FileStatus[] stats = fs.listStatus(path);
+ assertTrue(stats != null && stats.length == 1 && stats[0] == stat);
+ }
}