HDFS-9451. Clean up depreated umasks and related unit tests. Contributed by Wei-Chiu Chuang.

This commit is contained in:
Haohui Mai 2015-11-25 12:47:24 -08:00
parent 95d5227c75
commit b21dffb1fe
4 changed files with 8 additions and 35 deletions

View File

@ -215,9 +215,6 @@ public class FsPermission implements Writable {
otheraction.and(umask.otheraction.not())); otheraction.and(umask.otheraction.not()));
} }
/** umask property label deprecated key and code in getUMask method
* to accommodate it may be removed in version .23 */
public static final String DEPRECATED_UMASK_LABEL = "dfs.umask";
public static final String UMASK_LABEL = public static final String UMASK_LABEL =
CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY; CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY;
public static final int DEFAULT_UMASK = public static final int DEFAULT_UMASK =
@ -236,8 +233,6 @@ public class FsPermission implements Writable {
* '-' sets bits in the mask. * '-' sets bits in the mask.
* *
* Octal umask, the specified bits are set in the file mode creation mask. * Octal umask, the specified bits are set in the file mode creation mask.
*
* {@code DEPRECATED_UMASK_LABEL} config param has umask value set to decimal.
*/ */
public static FsPermission getUMask(Configuration conf) { public static FsPermission getUMask(Configuration conf) {
int umask = DEFAULT_UMASK; int umask = DEFAULT_UMASK;
@ -246,7 +241,6 @@ public class FsPermission implements Writable {
// If the deprecated key is not present then check for the new key // If the deprecated key is not present then check for the new key
if(conf != null) { if(conf != null) {
String confUmask = conf.get(UMASK_LABEL); String confUmask = conf.get(UMASK_LABEL);
int oldUmask = conf.getInt(DEPRECATED_UMASK_LABEL, Integer.MIN_VALUE);
try { try {
if(confUmask != null) { if(confUmask != null) {
umask = new UmaskParser(confUmask).getUMask(); umask = new UmaskParser(confUmask).getUMask();
@ -290,7 +284,6 @@ public class FsPermission implements Writable {
/** Set the user file creation mask (umask) */ /** Set the user file creation mask (umask) */
public static void setUMask(Configuration conf, FsPermission umask) { public static void setUMask(Configuration conf, FsPermission umask) {
conf.set(UMASK_LABEL, String.format("%1$03o", umask.toShort())); conf.set(UMASK_LABEL, String.format("%1$03o", umask.toShort()));
conf.setInt(DEPRECATED_UMASK_LABEL, umask.toShort());
} }
/** /**

View File

@ -695,14 +695,4 @@ public class TestFsPermission extends TestCase {
msg.contains(umask) && msg.contains(umask) &&
msg.contains("octal or symbolic"); msg.contains("octal or symbolic");
} }
// Ensure that when the deprecated decimal umask key is used, it is correctly
// parsed as such and converted correctly to an FsPermission value
public void testDeprecatedUmask() {
Configuration conf = new Configuration();
conf.set(FsPermission.DEPRECATED_UMASK_LABEL, "302"); // 302 = 0456
FsPermission umask = FsPermission.getUMask(conf);
assertEquals(0456, umask.toShort());
}
} }

View File

@ -868,6 +868,9 @@ Trunk (Unreleased)
HDFS-9348. Erasure Coding: DFS GetErasureCodingPolicy API on a non-existent HDFS-9348. Erasure Coding: DFS GetErasureCodingPolicy API on a non-existent
file should be handled properly. (Rakesh R via umamahesh) file should be handled properly. (Rakesh R via umamahesh)
HDFS-9451. Clean up depreated umasks and related unit tests.
(Wei-Chiu Chuang via wheat9)
Release 2.8.0 - UNRELEASED Release 2.8.0 - UNRELEASED
NEW FEATURES NEW FEATURES

View File

@ -84,30 +84,17 @@ public class TestPermission {
FsPermission.setUMask(conf, perm); FsPermission.setUMask(conf, perm);
assertEquals(18, FsPermission.getUMask(conf).toShort()); assertEquals(18, FsPermission.getUMask(conf).toShort());
// Test 2 - old configuration key set with decimal // Test 2 - new configuration key is handled
// umask value should be handled
perm = new FsPermission((short)18);
conf = new Configuration();
conf.set(FsPermission.DEPRECATED_UMASK_LABEL, "18");
assertEquals(18, FsPermission.getUMask(conf).toShort());
// Test 3 - old configuration key overrides the new one
conf = new Configuration();
conf.set(FsPermission.DEPRECATED_UMASK_LABEL, "18");
conf.set(FsPermission.UMASK_LABEL, "000");
assertEquals(18, FsPermission.getUMask(conf).toShort());
// Test 4 - new configuration key is handled
conf = new Configuration(); conf = new Configuration();
conf.set(FsPermission.UMASK_LABEL, "022"); conf.set(FsPermission.UMASK_LABEL, "022");
assertEquals(18, FsPermission.getUMask(conf).toShort()); assertEquals(18, FsPermission.getUMask(conf).toShort());
// Test 5 - equivalent valid umask // Test 3 - equivalent valid umask
conf = new Configuration(); conf = new Configuration();
conf.set(FsPermission.UMASK_LABEL, "0022"); conf.set(FsPermission.UMASK_LABEL, "0022");
assertEquals(18, FsPermission.getUMask(conf).toShort()); assertEquals(18, FsPermission.getUMask(conf).toShort());
// Test 6 - invalid umask // Test 4 - invalid umask
conf = new Configuration(); conf = new Configuration();
conf.set(FsPermission.UMASK_LABEL, "1222"); conf.set(FsPermission.UMASK_LABEL, "1222");
try { try {
@ -117,7 +104,7 @@ public class TestPermission {
//pass, exception successfully trigger //pass, exception successfully trigger
} }
// Test 7 - invalid umask // Test 5 - invalid umask
conf = new Configuration(); conf = new Configuration();
conf.set(FsPermission.UMASK_LABEL, "01222"); conf.set(FsPermission.UMASK_LABEL, "01222");
try { try {