Przeglądaj źródła

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.
+


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-patches@1077023 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley 14 lat temu
rodzic
commit
6b418bd72e

+ 51 - 2
src/core/org/apache/hadoop/fs/RawLocalFileSystem.java

@@ -470,10 +470,59 @@ public class RawLocalFileSystem extends FileSystem {
   @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);