HADOOP-7818. DiskChecker#checkDir should fail if the directory is not executable. Contributed by Madhukara Phatak. (harsh)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1361717 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
385f31ad85
commit
7351a01259
@ -258,6 +258,9 @@ Branch-2 ( Unreleased changes )
|
||||
called with a null key or value. (Madhukara Phatak
|
||||
and Suresh Srinivas via harsh)
|
||||
|
||||
HADOOP-7818. DiskChecker#checkDir should fail if the directory is
|
||||
not executable. (Madhukara Phatak via harsh)
|
||||
|
||||
BUG FIXES
|
||||
|
||||
HADOOP-8372. NetUtils.normalizeHostName() incorrectly handles hostname
|
||||
|
@ -78,26 +78,32 @@ public static boolean mkdirsWithExistsCheck(File dir) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the directory if it doesn't exist and
|
||||
* Create the directory if it doesn't exist and check that dir is readable,
|
||||
* writable and executable
|
||||
*
|
||||
* @param dir
|
||||
* @throws DiskErrorException
|
||||
*/
|
||||
public static void checkDir(File dir) throws DiskErrorException {
|
||||
if (!mkdirsWithExistsCheck(dir))
|
||||
throw new DiskErrorException("can not create directory: "
|
||||
throw new DiskErrorException("Can not create directory: "
|
||||
+ dir.toString());
|
||||
|
||||
|
||||
if (!dir.isDirectory())
|
||||
throw new DiskErrorException("not a directory: "
|
||||
throw new DiskErrorException("Not a directory: "
|
||||
+ dir.toString());
|
||||
|
||||
|
||||
if (!dir.canRead())
|
||||
throw new DiskErrorException("directory is not readable: "
|
||||
throw new DiskErrorException("Directory is not readable: "
|
||||
+ dir.toString());
|
||||
|
||||
|
||||
if (!dir.canWrite())
|
||||
throw new DiskErrorException("directory is not writable: "
|
||||
throw new DiskErrorException("Directory is not writable: "
|
||||
+ dir.toString());
|
||||
|
||||
if (!dir.canExecute())
|
||||
throw new DiskErrorException("Directory is not executable: "
|
||||
+ dir.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,4 +124,53 @@ private void _checkDirs(boolean isDir, FsPermission perm, boolean success)
|
||||
}
|
||||
System.out.println("checkDir success: "+ success);
|
||||
}
|
||||
|
||||
/**
|
||||
* These test cases test to test the creation of a local folder with correct
|
||||
* permission for result of mapper.
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testCheckDir_normal_local() throws Throwable {
|
||||
_checkDirs(true, "755", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckDir_notDir_local() throws Throwable {
|
||||
_checkDirs(false, "000", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckDir_notReadable_local() throws Throwable {
|
||||
_checkDirs(true, "000", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckDir_notWritable_local() throws Throwable {
|
||||
_checkDirs(true, "444", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckDir_notListable_local() throws Throwable {
|
||||
_checkDirs(true, "666", false);
|
||||
}
|
||||
|
||||
private void _checkDirs(boolean isDir, String perm, boolean success)
|
||||
throws Throwable {
|
||||
File localDir = File.createTempFile("test", "tmp");
|
||||
localDir.delete();
|
||||
localDir.mkdir();
|
||||
Runtime.getRuntime().exec(
|
||||
"chmod " + perm + " " + localDir.getAbsolutePath()).waitFor();
|
||||
try {
|
||||
DiskChecker.checkDir(localDir);
|
||||
assertTrue("checkDir success", success);
|
||||
} catch (DiskErrorException e) {
|
||||
e.printStackTrace();
|
||||
assertFalse("checkDir success", success);
|
||||
}
|
||||
localDir.delete();
|
||||
System.out.println("checkDir success: " + success);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user