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 sh...@apache.org on 2008/03/28 21:55:47 UTC

svn commit: r642376 - in /hadoop/core/trunk: CHANGES.txt src/java/org/apache/hadoop/dfs/DistributedFileSystem.java src/java/org/apache/hadoop/dfs/FSDirectory.java src/test/org/apache/hadoop/security/TestPermission.java

Author: shv
Date: Fri Mar 28 13:55:45 2008
New Revision: 642376

URL: http://svn.apache.org/viewvc?rev=642376&view=rev
Log:
HADOOP-3108. Fix NPE in setPermission and setOwner. Contributed by Konstantin Shvachko.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java
    hadoop/core/trunk/src/test/org/apache/hadoop/security/TestPermission.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=642376&r1=642375&r2=642376&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Fri Mar 28 13:55:45 2008
@@ -1257,6 +1257,8 @@
     HADOOP-2768. Fix performance regression caused by HADOOP-1707.
     (dhruba borthakur via nigel)
 
+    HADOOP-3108. Fix NPE in setPermission and setOwner. (shv)
+
 Release 0.15.3 - 2008-01-18
 
   BUG FIXES

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java?rev=642376&r1=642375&r2=642376&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java Fri Mar 28 13:55:45 2008
@@ -396,7 +396,13 @@
   /** {@inheritDoc }*/
   public void setPermission(Path p, FsPermission permission
       ) throws IOException {
-    dfs.namenode.setPermission(getPathName(p), permission);
+    try {
+      dfs.namenode.setPermission(getPathName(p), permission);
+    } catch(RemoteException re) {
+      if(FileNotFoundException.class.getName().equals(re.getClassName())) {
+        throw new FileNotFoundException("File does not exist: " + p);
+      }
+    }
   }
 
   /** {@inheritDoc }*/
@@ -405,6 +411,12 @@
     if (username == null && groupname == null) {
       throw new IOException("username == null && groupname == null");
     }
-    dfs.namenode.setOwner(getPathName(p), username, groupname);
+    try {
+      dfs.namenode.setOwner(getPathName(p), username, groupname);
+    } catch(RemoteException re) {
+      if(FileNotFoundException.class.getName().equals(re.getClassName())) {
+        throw new FileNotFoundException("File does not exist: " + p);
+      }
+    }
   }
 }

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java?rev=642376&r1=642375&r2=642376&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java Fri Mar 28 13:55:45 2008
@@ -415,9 +415,12 @@
     fsImage.getEditLog().logSetPermissions(src, permission);
   }
 
-  void unprotectedSetPermission(String src, FsPermission permissions) {
+  void unprotectedSetPermission(String src, FsPermission permissions) throws FileNotFoundException {
     synchronized(rootDir) {
-      rootDir.getNode(src).setPermission(permissions);
+        INode inode = rootDir.getNode(src);
+        if(inode == null)
+            throw new FileNotFoundException("File does not exist: " + src);
+        inode.setPermission(permissions);
     }
   }
 
@@ -427,9 +430,11 @@
     fsImage.getEditLog().logSetOwner(src, username, groupname);
   }
 
-  void unprotectedSetOwner(String src, String username, String groupname) {
+  void unprotectedSetOwner(String src, String username, String groupname) throws FileNotFoundException {
     synchronized(rootDir) {
       INode inode = rootDir.getNode(src);
+      if(inode == null)
+          throw new FileNotFoundException("File does not exist: " + src);
       if (username != null) {
         inode.setUser(username);
       }

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/security/TestPermission.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/security/TestPermission.java?rev=642376&r1=642375&r2=642376&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/security/TestPermission.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/security/TestPermission.java Fri Mar 28 13:55:45 2008
@@ -119,6 +119,22 @@
     FileSystem fs = FileSystem.get(conf);
 
     try {
+      // test permissions on files that do not exist
+      assertFalse(fs.exists(CHILD_FILE1));
+      try {
+        fs.setOwner(CHILD_FILE1, "foo", "bar");
+        assertTrue(false);
+      }
+      catch(java.io.FileNotFoundException e) {
+        LOG.info("GOOD: got " + e);
+      }
+      try {
+        fs.setPermission(CHILD_FILE1, new FsPermission((short)0777));
+        assertTrue(false);
+      }
+      catch(java.io.FileNotFoundException e) {
+        LOG.info("GOOD: got " + e);
+      }
       // following dir/file creations are legal
       fs.mkdirs(CHILD_DIR1);
       FSDataOutputStream out = fs.create(CHILD_FILE1);