hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject svn commit: r1077023 - /hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java
Date Fri, 04 Mar 2011 03:31:10 GMT
Author: omalley
Date: Fri Mar  4 03:31:10 2011
New Revision: 1077023

URL: http://svn.apache.org/viewvc?rev=1077023&view=rev
Log:
commit e8ad50481cc3c67ec00fb1e4733a5bc5b58de8b1
Author: Arun C Murthy <acmurthy@apache.org>
Date:   Sun Oct 18 23:19:27 2009 -0700

    HADOOP:6304 from https://issues.apache.org/jira/secure/attachment/12422525/HADOOP-6304_yhadoop20.patch
    
    +++ b/YAHOO-CHANGES.txt
    +yahoo-hadoop-0.20.1-3041192001
    +
    +    HADOOP-6304. Use java.io.File.set{Readable|Writable|Executable} where
    +    possible in RawLocalFileSystem. Contributed by Arun C. Murthy.
    +

Modified:
    hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java

Modified: hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java?rev=1077023&r1=1077022&r2=1077023&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java
(original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/RawLocalFileSystem.java
Fri Mar  4 03:31:10 2011
@@ -470,10 +470,59 @@ public class RawLocalFileSystem extends 
   @Override
   public void setPermission(Path p, FsPermission permission
       ) throws IOException {
-    execCommand(pathToFile(p), Shell.SET_PERMISSION_COMMAND,
-        String.format("%04o", permission.toShort()));
+    FsAction user = permission.getUserAction();
+    FsAction group = permission.getGroupAction();
+    FsAction other = permission.getOtherAction();
+    
+    File f = pathToFile(p);
+    
+    // Fork chmod if group and other permissions are different...
+    if (group != other) {
+      execSetPermission(f, permission);
+      return;
+    }
+    
+    boolean rv = true;
+    
+    // read perms
+    rv = f.setReadable(group.implies(FsAction.READ), false);
+    checkReturnValue(rv, p, permission);
+    if (group.implies(FsAction.READ) != user.implies(FsAction.READ)) {
+      f.setReadable(user.implies(FsAction.READ), true);
+      checkReturnValue(rv, p, permission);
+    }
+
+    // write perms
+    rv = f.setWritable(group.implies(FsAction.WRITE), false);
+    checkReturnValue(rv, p, permission);
+    if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) {
+      f.setWritable(user.implies(FsAction.WRITE), true);
+      checkReturnValue(rv, p, permission);
+    }
+
+    // exec perms
+    rv = f.setExecutable(group.implies(FsAction.EXECUTE), false);
+    checkReturnValue(rv, p, permission);
+    if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) {
+      f.setExecutable(user.implies(FsAction.EXECUTE), true);
+      checkReturnValue(rv, p, permission);
+    }
   }
 
+  private void checkReturnValue(boolean rv, Path p, FsPermission permission) 
+  throws IOException {
+    if (!rv) {
+      throw new IOException("Failed to set permissions of path: " + p + " to " + 
+                            String.format("%04o", permission.toShort()));
+    }
+  }
+  
+  private void execSetPermission(File f, FsPermission permission) 
+  throws IOException {
+    execCommand(f, Shell.SET_PERMISSION_COMMAND,
+        String.format("%04o", permission.toShort()));
+  }
+  
   private static String execCommand(File f, String... cmd) throws IOException {
     String[] args = new String[cmd.length + 1];
     System.arraycopy(cmd, 0, args, 0, cmd.length);



Mime
View raw message