浏览代码

HADOOP-8955. chmod executable not found on Windows. Contributed by Chris Nauroth.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-trunk-win@1402167 13f79535-47bb-0310-9956-ffa450edef68
Suresh Srinivas 12 年之前
父节点
当前提交
52de02d312

+ 3 - 0
hadoop-common-project/hadoop-common/CHANGES.branch-trunk-win.txt

@@ -20,3 +20,6 @@ branch-trunk-win changes - unreleased
 
 
   HADOOP-8959. TestUserGroupInformation fails on Windows due to "id" executable
   HADOOP-8959. TestUserGroupInformation fails on Windows due to "id" executable
   not found. (Bikas Saha, Ivan Mitic, ported by Chris Narouth via suresh)
   not found. (Bikas Saha, Ivan Mitic, ported by Chris Narouth via suresh)
+
+  HADOOP-8955. "chmod" executable not found on Windows.
+  (Chris Nauroth via suresh)

+ 17 - 0
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java

@@ -21,6 +21,7 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.InputStreamReader;
+import java.util.Arrays;
 import java.util.Map;
 import java.util.Map;
 import java.util.Timer;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.TimerTask;
@@ -91,6 +92,22 @@ abstract public class Shell {
     }
     }
   }
   }
 
 
+  /**
+   * Return a command to set permission for specific file.
+   * 
+   * @param perm String permission to set
+   * @param recursive boolean true to apply to all sub-directories recursively
+   * @param file String file to set
+   * @return String[] containing command and arguments
+   */
+  public static String[] getSetPermissionCommand(String perm, boolean recursive,
+                                                 String file) {
+    String[] baseCmd = getSetPermissionCommand(perm, recursive);
+    String[] cmdWithFile = Arrays.copyOf(baseCmd, baseCmd.length + 1);
+    cmdWithFile[cmdWithFile.length - 1] = file;
+    return cmdWithFile;
+  }
+
   /** Return a command to set owner */
   /** Return a command to set owner */
   public static String[] getSetOwnerCommand(String owner) {
   public static String[] getSetOwnerCommand(String owner) {
     return (WINDOWS) ? new String[] { WINUTILS, "chown", owner }
     return (WINDOWS) ? new String[] { WINUTILS, "chown", owner }

+ 10 - 5
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java

@@ -138,7 +138,8 @@ public class TestLocalDirAllocator {
       validateTempDirCreation(dir1);
       validateTempDirCreation(dir1);
       validateTempDirCreation(dir1);
       validateTempDirCreation(dir1);
     } finally {
     } finally {
-      Shell.execCommand(new String[]{"chmod", "u+w", BUFFER_DIR_ROOT});
+      Shell.execCommand(Shell.getSetPermissionCommand("u+w", false,
+                                                      BUFFER_DIR_ROOT));
       rmBufferDirs();
       rmBufferDirs();
     }
     }
   }
   }
@@ -159,7 +160,8 @@ public class TestLocalDirAllocator {
       validateTempDirCreation(dir2);
       validateTempDirCreation(dir2);
       validateTempDirCreation(dir2);
       validateTempDirCreation(dir2);
     } finally {
     } finally {
-      Shell.execCommand(new String[]{"chmod", "u+w", BUFFER_DIR_ROOT});
+      Shell.execCommand(Shell.getSetPermissionCommand("u+w", false,
+                                                      BUFFER_DIR_ROOT));
       rmBufferDirs();
       rmBufferDirs();
     }
     }
   }
   }
@@ -288,7 +290,8 @@ public class TestLocalDirAllocator {
         assertEquals(e.getClass(), FileNotFoundException.class);
         assertEquals(e.getClass(), FileNotFoundException.class);
       }
       }
     } finally {
     } finally {
-      Shell.execCommand(new String[] { "chmod", "u+w", BUFFER_DIR_ROOT });
+      Shell.execCommand(Shell.getSetPermissionCommand("u+w", false,
+                                                      BUFFER_DIR_ROOT));
       rmBufferDirs();
       rmBufferDirs();
     }
     }
   }
   }
@@ -327,7 +330,8 @@ public class TestLocalDirAllocator {
       assertTrue(result.getParentFile().delete());
       assertTrue(result.getParentFile().delete());
       assertFalse(new File(dir).exists());
       assertFalse(new File(dir).exists());
     } finally {
     } finally {
-      Shell.execCommand(new String[]{"chmod", "u+w", BUFFER_DIR_ROOT});
+      Shell.execCommand(Shell.getSetPermissionCommand("u+w", false,
+                                                      BUFFER_DIR_ROOT));
       rmBufferDirs();
       rmBufferDirs();
     }
     }
   }
   }
@@ -351,7 +355,8 @@ public class TestLocalDirAllocator {
       assertEquals(f1.getName(), p1.getName());
       assertEquals(f1.getName(), p1.getName());
       assertEquals("file", p1.getFileSystem(conf).getUri().getScheme());
       assertEquals("file", p1.getFileSystem(conf).getUri().getScheme());
     } finally {
     } finally {
-      Shell.execCommand(new String[] { "chmod", "u+w", BUFFER_DIR_ROOT });
+      Shell.execCommand(Shell.getSetPermissionCommand("u+w", false,
+                                                      BUFFER_DIR_ROOT));
       rmBufferDirs();
       rmBufferDirs();
     }
     }
 
 

+ 3 - 2
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestDiskChecker.java

@@ -30,6 +30,7 @@ import org.apache.hadoop.fs.LocalFileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.util.DiskChecker.DiskErrorException;
 import org.apache.hadoop.util.DiskChecker.DiskErrorException;
+import org.apache.hadoop.util.Shell;
 
 
 public class TestDiskChecker {
 public class TestDiskChecker {
   final FsPermission defaultPerm = new FsPermission("755");
   final FsPermission defaultPerm = new FsPermission("755");
@@ -160,8 +161,8 @@ public class TestDiskChecker {
     File localDir = File.createTempFile("test", "tmp");
     File localDir = File.createTempFile("test", "tmp");
     localDir.delete();
     localDir.delete();
     localDir.mkdir();
     localDir.mkdir();
-    Runtime.getRuntime().exec(
-	"chmod " + perm + "  " + localDir.getAbsolutePath()).waitFor();
+    Shell.execCommand(Shell.getSetPermissionCommand(perm, false,
+                                                    localDir.getAbsolutePath()));
     try {
     try {
       DiskChecker.checkDir(localDir);
       DiskChecker.checkDir(localDir);
       assertTrue("checkDir success", success);
       assertTrue("checkDir success", success);

+ 2 - 2
hadoop-tools/hadoop-streaming/src/test/java/org/apache/hadoop/streaming/TestStreamingTaskLog.java

@@ -124,8 +124,8 @@ public class TestStreamingTaskLog {
               "echo $HADOOP_ROOT_LOGGER $HADOOP_CLIENT_OPTS").getBytes());
               "echo $HADOOP_ROOT_LOGGER $HADOOP_CLIENT_OPTS").getBytes());
     in.close();
     in.close();
     
     
-    Shell.execCommand(new String[]{"chmod", "+x",
-                                   scriptFile.getAbsolutePath()});
+    Shell.execCommand(Shell.getSetPermissionCommand("+x", false,
+        scriptFile.getAbsolutePath()));
     return scriptFile;
     return scriptFile;
   }
   }