瀏覽代碼

MAPREDUCE-2073. TestTrackerDistributedCacheManager should be up-front about requirements on build environment. Contributed by Todd Lipcon

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security@1203899 13f79535-47bb-0310-9956-ffa450edef68
Eli Collins 13 年之前
父節點
當前提交
dd64d518da

+ 3 - 0
CHANGES.txt

@@ -32,6 +32,9 @@ Release 0.20.206.0 - unreleased
     MAPREDUCE-3405. Fix compilation in contrib tests broken by commit
     of MAPREDUCE-3015. (todd)
 
+    MAPREDUCE-2073. TestTrackerDistributedCacheManager should be
+    up-front about requirements on build environment. (todd)
+
   IMPROVEMENTS
 
     MAPREDUCE-2836. Provide option to fail jobs when submitted to

+ 12 - 1
src/mapred/org/apache/hadoop/filecache/TrackerDistributedCacheManager.java

@@ -325,7 +325,17 @@ public class TrackerDistributedCacheManager {
     if (!checkPermissionOfOther(fs, current, FsAction.READ)) {
       return false;
     }
-    current = current.getParent();
+    return ancestorsHaveExecutePermissions(fs, current.getParent());
+  }
+
+  /**
+   * Returns true if all ancestors of the specified path have the 'execute'
+   * permission set for all users (i.e. that other users can traverse
+   * the directory heirarchy to the given path)
+   */
+  static boolean ancestorsHaveExecutePermissions(FileSystem fs, Path path)
+    throws IOException {
+    Path current = path;
     while (current != null) {
       //the subdirs in the path should have execute permissions for others
       if (!checkPermissionOfOther(fs, current, FsAction.EXECUTE)) {
@@ -335,6 +345,7 @@ public class TrackerDistributedCacheManager {
     }
     return true;
   }
+
   /**
    * Checks for a given path whether the Other permissions on it 
    * imply the permission in the passed FsAction

+ 13 - 3
src/test/org/apache/hadoop/filecache/TestTrackerDistributedCacheManager.java

@@ -92,6 +92,19 @@ public class TestTrackerDistributedCacheManager extends TestCase {
       TEST_ROOT.mkdirs();
     }
 
+    conf = new Configuration();
+    conf.set(FileSystem.FS_DEFAULT_NAME_KEY, "file:///");
+    fs = FileSystem.get(conf);
+
+    // This test suite will fail if any ancestor directory of the
+    // test directory is not world-searchable (ie +x).
+    // We prefer to fail the test in an obvious manner up front
+    // during setUp() rather than in a subtle way later.
+    assertTrue("Test root directory " + TEST_ROOT + " and all of its " +
+               "parent directories must have a+x permissions",
+               TrackerDistributedCacheManager.ancestorsHaveExecutePermissions(
+                 fs, new Path(TEST_ROOT.toString())));
+
     // Prepare the tests' mapred-local-dir
     ROOT_MAPRED_LOCAL_DIR = new File(TEST_ROOT_DIR, "mapred/local");
     ROOT_MAPRED_LOCAL_DIR.mkdirs();
@@ -103,10 +116,7 @@ public class TestTrackerDistributedCacheManager extends TestCase {
       localDir.mkdir();
     }
 
-    conf = new Configuration();
     conf.setStrings("mapred.local.dir", localDirs);
-    conf.set(FileSystem.FS_DEFAULT_NAME_KEY, "file:///");
-    fs = FileSystem.get(conf);
     Class<? extends TaskController> taskControllerClass = conf.getClass(
         "mapred.task.tracker.task-controller", DefaultTaskController.class,
         TaskController.class);