hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1143491 - in /hadoop/common/trunk/common: CHANGES.txt src/java/org/apache/hadoop/fs/FileSystem.java src/test/core/org/apache/hadoop/fs/FSMainOperationsBaseTest.java
Date Wed, 06 Jul 2011 16:37:20 GMT
Author: mattf
Date: Wed Jul  6 16:37:19 2011
New Revision: 1143491

URL: http://svn.apache.org/viewvc?rev=1143491&view=rev
Log:
HADOOP-7327. FileSystem.listStatus() throws NullPointerException instead of IOException upon
access permission failure. Contributed by Matt Foley.

Modified:
    hadoop/common/trunk/common/CHANGES.txt
    hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/FileSystem.java
    hadoop/common/trunk/common/src/test/core/org/apache/hadoop/fs/FSMainOperationsBaseTest.java

Modified: hadoop/common/trunk/common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/CHANGES.txt?rev=1143491&r1=1143490&r2=1143491&view=diff
==============================================================================
--- hadoop/common/trunk/common/CHANGES.txt (original)
+++ hadoop/common/trunk/common/CHANGES.txt Wed Jul  6 16:37:19 2011
@@ -246,6 +246,9 @@ Trunk (unreleased changes)
 
   BUG FIXES
 
+    HADOOP-7327. FileSystem.listStatus() throws NullPointerException instead of
+    IOException upon access permission failure. (mattf)
+
     HADOOP-7015. RawLocalFileSystem#listStatus does not deal with a directory
     whose entries are changing (e.g. in a multi-thread or multi-process
     environment). (Sanjay Radia via eli)

Modified: hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/FileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/FileSystem.java?rev=1143491&r1=1143490&r2=1143491&view=diff
==============================================================================
--- hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/FileSystem.java (original)
+++ hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/FileSystem.java Wed Jul  6 16:37:19
2011
@@ -1151,6 +1151,9 @@ public abstract class FileSystem extends
   private void listStatus(ArrayList<FileStatus> results, Path f,
       PathFilter filter) throws FileNotFoundException, IOException {
     FileStatus listing[] = listStatus(f);
+    if (listing == null) {
+      throw new IOException("Error accessing " + f);
+    }
 
     for (int i = 0; i < listing.length; i++) {
       if (filter.accept(listing[i].getPath())) {

Modified: hadoop/common/trunk/common/src/test/core/org/apache/hadoop/fs/FSMainOperationsBaseTest.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/test/core/org/apache/hadoop/fs/FSMainOperationsBaseTest.java?rev=1143491&r1=1143490&r2=1143491&view=diff
==============================================================================
--- hadoop/common/trunk/common/src/test/core/org/apache/hadoop/fs/FSMainOperationsBaseTest.java
(original)
+++ hadoop/common/trunk/common/src/test/core/org/apache/hadoop/fs/FSMainOperationsBaseTest.java
Wed Jul  6 16:37:19 2011
@@ -25,6 +25,7 @@ import java.io.InputStream;
 
 
 import org.apache.hadoop.fs.Options.Rename;
+import org.apache.hadoop.fs.permission.FsPermission;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -252,8 +253,9 @@ public abstract class FSMainOperationsBa
     }
   } 
   
+  @Test
   public void testListStatusThrowsExceptionForNonExistentFile()
-                                                    throws Exception {
+  throws Exception {
     try {
       fSys.listStatus(getTestRootPath(fSys, "test/hadoop/file"));
       Assert.fail("Should throw FileNotFoundException");
@@ -262,6 +264,27 @@ public abstract class FSMainOperationsBa
     }
   }
   
+  // TODO: update after fixing HADOOP-7352
+  @Test
+  public void testListStatusThrowsExceptionForUnreadableDir()
+  throws Exception {
+    Path testRootDir = getTestRootPath(fSys, "test/hadoop/dir");
+    Path obscuredDir = new Path(testRootDir, "foo");
+    Path subDir = new Path(obscuredDir, "bar"); //so foo is non-empty
+    fSys.mkdirs(subDir);
+    fSys.setPermission(obscuredDir, new FsPermission((short)0)); //no access
+    try {
+      fSys.listStatus(obscuredDir);
+      Assert.fail("Should throw IOException");
+    } catch (IOException ioe) {
+      // expected
+    } finally {
+      // make sure the test directory can be deleted
+      fSys.setPermission(obscuredDir, new FsPermission((short)0755)); //default
+    }
+  }
+
+
   @Test
   public void testListStatus() throws Exception {
     Path[] testDirs = {
@@ -315,6 +338,7 @@ public abstract class FSMainOperationsBa
     
   }
   
+  @Test
   public void testListStatusFilterWithSomeMatches() throws Exception {
     Path[] testDirs = {
         getTestRootPath(fSys, TEST_DIR_AAA),
@@ -919,12 +943,13 @@ public abstract class FSMainOperationsBa
 
   @Test
   public void testRenameDirectoryAsNonExistentDirectory() throws Exception {
-    testRenameDirectoryAsNonExistentDirectory(Rename.NONE);
+    doTestRenameDirectoryAsNonExistentDirectory(Rename.NONE);
     tearDown();
-    testRenameDirectoryAsNonExistentDirectory(Rename.OVERWRITE);
+    doTestRenameDirectoryAsNonExistentDirectory(Rename.OVERWRITE);
   }
 
-  private void testRenameDirectoryAsNonExistentDirectory(Rename... options) throws Exception
{
+  private void doTestRenameDirectoryAsNonExistentDirectory(Rename... options) 
+  throws Exception {
     if (!renameSupported()) return;
     
     Path src = getTestRootPath(fSys, "test/hadoop/dir");



Mime
View raw message