Browse Source

HADOOP-3108. Correction to the previous patch. Contributed by Konstantin Shvachko.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.16@642372 13f79535-47bb-0310-9956-ffa450edef68
Konstantin Shvachko 17 years ago
parent
commit
ea8947119d

+ 2 - 0
CHANGES.txt

@@ -851,6 +851,8 @@ Release 0.16.0 - 2008-02-07
 
 
     HADOOP-3108. Fix NPE in setPermission and setOwner. (shv)
     HADOOP-3108. Fix NPE in setPermission and setOwner. (shv)
 
 
+    HADOOP-3108. Correction to the previous patch. (shv)
+
 Release 0.15.3 - 2008-01-18
 Release 0.15.3 - 2008-01-18
 
 
   BUG FIXES
   BUG FIXES

+ 14 - 2
src/java/org/apache/hadoop/dfs/DistributedFileSystem.java

@@ -352,7 +352,13 @@ public class DistributedFileSystem extends FileSystem {
   /** {@inheritDoc }*/
   /** {@inheritDoc }*/
   public void setPermission(Path p, FsPermission permission
   public void setPermission(Path p, FsPermission permission
       ) throws IOException {
       ) 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 }*/
   /** {@inheritDoc }*/
@@ -361,6 +367,12 @@ public class DistributedFileSystem extends FileSystem {
     if (username == null && groupname == null) {
     if (username == null && groupname == null) {
       throw new IOException("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);
+      }
+    }
   }
   }
 }
 }

+ 16 - 16
src/test/org/apache/hadoop/security/TestPermission.java

@@ -119,22 +119,22 @@ public class TestPermission extends TestCase {
     FileSystem fs = FileSystem.get(conf);
     FileSystem fs = FileSystem.get(conf);
 
 
     try {
     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);
-        }
+      // 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
       // following dir/file creations are legal
       fs.mkdirs(CHILD_DIR1);
       fs.mkdirs(CHILD_DIR1);
       FSDataOutputStream out = fs.create(CHILD_FILE1);
       FSDataOutputStream out = fs.create(CHILD_FILE1);