HDFS-12250. Reduce usage of FsPermissionExtension in unit tests. Contributed by Chris Douglas.

This commit is contained in:
Andrew Wang 2017-08-17 09:35:36 -07:00
parent f9a0e23381
commit dd7916d3cd
11 changed files with 33 additions and 29 deletions

View File

@ -163,7 +163,7 @@ public FsPermission getUnmasked() {
*/ */
public static FsPermission read(DataInput in) throws IOException { public static FsPermission read(DataInput in) throws IOException {
FsPermission p = new FsPermission(); FsPermission p = new FsPermission();
p.readFields(in); p.fromShort(in.readShort());
return p; return p;
} }

View File

@ -86,9 +86,9 @@ protected void processPath(PathData item) throws IOException {
(perm.getOtherAction().implies(FsAction.EXECUTE) ? "t" : "T")); (perm.getOtherAction().implies(FsAction.EXECUTE) ? "t" : "T"));
} }
AclStatus aclStatus = null; final AclStatus aclStatus;
List<AclEntry> entries = null; final List<AclEntry> entries;
if (perm.getAclBit()) { if (item.stat.hasAcl()) {
aclStatus = item.fs.getAclStatus(item.path); aclStatus = item.fs.getAclStatus(item.path);
entries = aclStatus.getEntries(); entries = aclStatus.getEntries();
} else { } else {

View File

@ -444,8 +444,8 @@ protected void preserveAttributes(PathData src, PathData target,
src.stat.getPermission()); src.stat.getPermission());
} }
if (shouldPreserve(FileAttribute.ACL)) { if (shouldPreserve(FileAttribute.ACL)) {
FsPermission perm = src.stat.getPermission(); if (src.stat.hasAcl()) {
if (perm.getAclBit()) { FsPermission perm = src.stat.getPermission();
List<AclEntry> srcEntries = List<AclEntry> srcEntries =
src.fs.getAclStatus(src.path).getEntries(); src.fs.getAclStatus(src.path).getEntries();
List<AclEntry> srcFullEntries = List<AclEntry> srcFullEntries =

View File

@ -255,7 +255,7 @@ protected void processPath(PathData item) throws IOException {
ContentSummary contentSummary = item.fs.getContentSummary(item.path); ContentSummary contentSummary = item.fs.getContentSummary(item.path);
String line = String.format(lineFormat, String line = String.format(lineFormat,
(stat.isDirectory() ? "d" : "-"), (stat.isDirectory() ? "d" : "-"),
stat.getPermission() + (stat.getPermission().getAclBit() ? "+" : " "), stat.getPermission() + (stat.hasAcl() ? "+" : " "),
(stat.isFile() ? stat.getReplication() : "-"), (stat.isFile() ? stat.getReplication() : "-"),
stat.getOwner(), stat.getOwner(),
stat.getGroup(), stat.getGroup(),
@ -269,7 +269,7 @@ protected void processPath(PathData item) throws IOException {
} else { } else {
String line = String.format(lineFormat, String line = String.format(lineFormat,
(stat.isDirectory() ? "d" : "-"), (stat.isDirectory() ? "d" : "-"),
stat.getPermission() + (stat.getPermission().getAclBit() ? "+" : " "), stat.getPermission() + (stat.hasAcl() ? "+" : " "),
(stat.isFile() ? stat.getReplication() : "-"), (stat.isFile() ? stat.getReplication() : "-"),
stat.getOwner(), stat.getOwner(),
stat.getGroup(), stat.getGroup(),

View File

@ -859,6 +859,7 @@ private static void assertSameAcls(FileSystem expected, FileSystem actual,
FileStatus expectedFileStatus = expected.getFileStatus(path); FileStatus expectedFileStatus = expected.getFileStatus(path);
FileStatus actualFileStatus = actual.getFileStatus(path); FileStatus actualFileStatus = actual.getFileStatus(path);
assertEquals(actualFileStatus.hasAcl(), expectedFileStatus.hasAcl()); assertEquals(actualFileStatus.hasAcl(), expectedFileStatus.hasAcl());
// backwards compat
assertEquals(actualFileStatus.getPermission().getAclBit(), assertEquals(actualFileStatus.getPermission().getAclBit(),
expectedFileStatus.getPermission().getAclBit()); expectedFileStatus.getPermission().getAclBit());
} }

View File

@ -2189,7 +2189,7 @@ public void testCopyCommandsWithPreserveOption() throws Exception {
assertTrue(xattrs.isEmpty()); assertTrue(xattrs.isEmpty());
List<AclEntry> acls = dfs.getAclStatus(target1).getEntries(); List<AclEntry> acls = dfs.getAclStatus(target1).getEntries();
assertTrue(acls.isEmpty()); assertTrue(acls.isEmpty());
assertFalse(targetPerm.getAclBit()); assertFalse(targetStatus.hasAcl());
// -ptop // -ptop
Path target2 = new Path(hdfsTestDir, "targetfile2"); Path target2 = new Path(hdfsTestDir, "targetfile2");
@ -2208,7 +2208,7 @@ public void testCopyCommandsWithPreserveOption() throws Exception {
assertTrue(xattrs.isEmpty()); assertTrue(xattrs.isEmpty());
acls = dfs.getAclStatus(target2).getEntries(); acls = dfs.getAclStatus(target2).getEntries();
assertTrue(acls.isEmpty()); assertTrue(acls.isEmpty());
assertFalse(targetPerm.getAclBit()); assertFalse(targetStatus.hasAcl());
// -ptopx // -ptopx
Path target3 = new Path(hdfsTestDir, "targetfile3"); Path target3 = new Path(hdfsTestDir, "targetfile3");
@ -2229,7 +2229,7 @@ public void testCopyCommandsWithPreserveOption() throws Exception {
assertArrayEquals(TRUSTED_A1_VALUE, xattrs.get(TRUSTED_A1)); assertArrayEquals(TRUSTED_A1_VALUE, xattrs.get(TRUSTED_A1));
acls = dfs.getAclStatus(target3).getEntries(); acls = dfs.getAclStatus(target3).getEntries();
assertTrue(acls.isEmpty()); assertTrue(acls.isEmpty());
assertFalse(targetPerm.getAclBit()); assertFalse(targetStatus.hasAcl());
// -ptopa // -ptopa
Path target4 = new Path(hdfsTestDir, "targetfile4"); Path target4 = new Path(hdfsTestDir, "targetfile4");
@ -2248,7 +2248,7 @@ public void testCopyCommandsWithPreserveOption() throws Exception {
assertTrue(xattrs.isEmpty()); assertTrue(xattrs.isEmpty());
acls = dfs.getAclStatus(target4).getEntries(); acls = dfs.getAclStatus(target4).getEntries();
assertFalse(acls.isEmpty()); assertFalse(acls.isEmpty());
assertTrue(targetPerm.getAclBit()); assertTrue(targetStatus.hasAcl());
assertEquals(dfs.getAclStatus(src), dfs.getAclStatus(target4)); assertEquals(dfs.getAclStatus(src), dfs.getAclStatus(target4));
// -ptoa (verify -pa option will preserve permissions also) // -ptoa (verify -pa option will preserve permissions also)
@ -2268,7 +2268,7 @@ public void testCopyCommandsWithPreserveOption() throws Exception {
assertTrue(xattrs.isEmpty()); assertTrue(xattrs.isEmpty());
acls = dfs.getAclStatus(target5).getEntries(); acls = dfs.getAclStatus(target5).getEntries();
assertFalse(acls.isEmpty()); assertFalse(acls.isEmpty());
assertTrue(targetPerm.getAclBit()); assertTrue(targetStatus.hasAcl());
assertEquals(dfs.getAclStatus(src), dfs.getAclStatus(target5)); assertEquals(dfs.getAclStatus(src), dfs.getAclStatus(target5));
} finally { } finally {
if (null != shell) { if (null != shell) {
@ -2480,7 +2480,7 @@ public void testCopyCommandsToDirectoryWithPreserveOption()
assertTrue(xattrs.isEmpty()); assertTrue(xattrs.isEmpty());
List<AclEntry> acls = dfs.getAclStatus(targetDir1).getEntries(); List<AclEntry> acls = dfs.getAclStatus(targetDir1).getEntries();
assertTrue(acls.isEmpty()); assertTrue(acls.isEmpty());
assertFalse(targetPerm.getAclBit()); assertFalse(targetStatus.hasAcl());
// -ptop // -ptop
Path targetDir2 = new Path(hdfsTestDir, "targetDir2"); Path targetDir2 = new Path(hdfsTestDir, "targetDir2");
@ -2499,7 +2499,7 @@ public void testCopyCommandsToDirectoryWithPreserveOption()
assertTrue(xattrs.isEmpty()); assertTrue(xattrs.isEmpty());
acls = dfs.getAclStatus(targetDir2).getEntries(); acls = dfs.getAclStatus(targetDir2).getEntries();
assertTrue(acls.isEmpty()); assertTrue(acls.isEmpty());
assertFalse(targetPerm.getAclBit()); assertFalse(targetStatus.hasAcl());
// -ptopx // -ptopx
Path targetDir3 = new Path(hdfsTestDir, "targetDir3"); Path targetDir3 = new Path(hdfsTestDir, "targetDir3");
@ -2520,7 +2520,7 @@ public void testCopyCommandsToDirectoryWithPreserveOption()
assertArrayEquals(TRUSTED_A1_VALUE, xattrs.get(TRUSTED_A1)); assertArrayEquals(TRUSTED_A1_VALUE, xattrs.get(TRUSTED_A1));
acls = dfs.getAclStatus(targetDir3).getEntries(); acls = dfs.getAclStatus(targetDir3).getEntries();
assertTrue(acls.isEmpty()); assertTrue(acls.isEmpty());
assertFalse(targetPerm.getAclBit()); assertFalse(targetStatus.hasAcl());
// -ptopa // -ptopa
Path targetDir4 = new Path(hdfsTestDir, "targetDir4"); Path targetDir4 = new Path(hdfsTestDir, "targetDir4");
@ -2539,7 +2539,7 @@ public void testCopyCommandsToDirectoryWithPreserveOption()
assertTrue(xattrs.isEmpty()); assertTrue(xattrs.isEmpty());
acls = dfs.getAclStatus(targetDir4).getEntries(); acls = dfs.getAclStatus(targetDir4).getEntries();
assertFalse(acls.isEmpty()); assertFalse(acls.isEmpty());
assertTrue(targetPerm.getAclBit()); assertTrue(targetStatus.hasAcl());
assertEquals(dfs.getAclStatus(srcDir), dfs.getAclStatus(targetDir4)); assertEquals(dfs.getAclStatus(srcDir), dfs.getAclStatus(targetDir4));
// -ptoa (verify -pa option will preserve permissions also) // -ptoa (verify -pa option will preserve permissions also)
@ -2559,7 +2559,7 @@ public void testCopyCommandsToDirectoryWithPreserveOption()
assertTrue(xattrs.isEmpty()); assertTrue(xattrs.isEmpty());
acls = dfs.getAclStatus(targetDir5).getEntries(); acls = dfs.getAclStatus(targetDir5).getEntries();
assertFalse(acls.isEmpty()); assertFalse(acls.isEmpty());
assertTrue(targetPerm.getAclBit()); assertTrue(targetStatus.hasAcl());
assertEquals(dfs.getAclStatus(srcDir), dfs.getAclStatus(targetDir5)); assertEquals(dfs.getAclStatus(srcDir), dfs.getAclStatus(targetDir5));
} finally { } finally {
if (shell != null) { if (shell != null) {
@ -2615,7 +2615,7 @@ public void testCopyCommandsPreserveAclAndStickyBit() throws Exception {
assertTrue(perm.equals(targetPerm)); assertTrue(perm.equals(targetPerm));
List<AclEntry> acls = dfs.getAclStatus(target1).getEntries(); List<AclEntry> acls = dfs.getAclStatus(target1).getEntries();
assertTrue(acls.isEmpty()); assertTrue(acls.isEmpty());
assertFalse(targetPerm.getAclBit()); assertFalse(targetStatus.hasAcl());
// -ptopa preserves both sticky bit and ACL // -ptopa preserves both sticky bit and ACL
Path target2 = new Path(hdfsTestDir, "targetfile2"); Path target2 = new Path(hdfsTestDir, "targetfile2");
@ -2632,7 +2632,7 @@ public void testCopyCommandsPreserveAclAndStickyBit() throws Exception {
assertTrue(perm.equals(targetPerm)); assertTrue(perm.equals(targetPerm));
acls = dfs.getAclStatus(target2).getEntries(); acls = dfs.getAclStatus(target2).getEntries();
assertFalse(acls.isEmpty()); assertFalse(acls.isEmpty());
assertTrue(targetPerm.getAclBit()); assertTrue(targetStatus.hasAcl());
assertEquals(dfs.getAclStatus(src), dfs.getAclStatus(target2)); assertEquals(dfs.getAclStatus(src), dfs.getAclStatus(target2));
} finally { } finally {
if (null != shell) { if (null != shell) {

View File

@ -32,6 +32,7 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.AclEntry; import org.apache.hadoop.fs.permission.AclEntry;
@ -886,6 +887,11 @@ public void testSetPermissionCannotSetAclBit() throws IOException {
FsPermission perm = inode.getFsPermission(); FsPermission perm = inode.getFsPermission();
assertNotNull(perm); assertNotNull(perm);
assertEquals(0755, perm.toShort()); assertEquals(0755, perm.toShort());
FileStatus stat = fs.getFileStatus(path);
assertFalse(stat.hasAcl());
assertFalse(stat.isEncrypted());
assertFalse(stat.isErasureCoded());
// backwards-compat check
assertEquals(0755, perm.toExtendedShort()); assertEquals(0755, perm.toExtendedShort());
assertAclFeature(false); assertAclFeature(false);
} }

View File

@ -28,7 +28,6 @@
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.mapreduce.MRJobConfig; import org.apache.hadoop.mapreduce.MRJobConfig;
import org.apache.hadoop.mapreduce.security.TokenCache; import org.apache.hadoop.mapreduce.security.TokenCache;
import org.apache.hadoop.security.Credentials; import org.apache.hadoop.security.Credentials;
@ -293,7 +292,6 @@ static boolean ancestorsHaveExecutePermissions(FileSystem fs, Path path,
private static boolean checkPermissionOfOther(FileSystem fs, Path path, private static boolean checkPermissionOfOther(FileSystem fs, Path path,
FsAction action, Map<URI, FileStatus> statCache) throws IOException { FsAction action, Map<URI, FileStatus> statCache) throws IOException {
FileStatus status = getFileStatus(fs, path.toUri(), statCache); FileStatus status = getFileStatus(fs, path.toUri(), statCache);
FsPermission perms = status.getPermission();
// Encrypted files are always treated as private. This stance has two // Encrypted files are always treated as private. This stance has two
// important side effects. The first is that the encrypted files will be // important side effects. The first is that the encrypted files will be
@ -302,8 +300,8 @@ private static boolean checkPermissionOfOther(FileSystem fs, Path path,
// world readable permissions that is stored in an encryption zone from // world readable permissions that is stored in an encryption zone from
// being localized as a publicly shared file with world readable // being localized as a publicly shared file with world readable
// permissions. // permissions.
if (!perms.getEncryptedBit()) { if (!status.isEncrypted()) {
FsAction otherAction = perms.getOtherAction(); FsAction otherAction = status.getPermission().getOtherAction();
if (otherAction.implies(action)) { if (otherAction.implies(action)) {
return true; return true;
} }

View File

@ -98,4 +98,5 @@ public void getFileStatusAclBit() throws URISyntaxException, IOException {
Assert.assertFalse(fileStatus.hasAcl()); Assert.assertFalse(fileStatus.hasAcl());
Assert.assertFalse(fileStatus.getPermission().getAclBit()); Assert.assertFalse(fileStatus.getPermission().getAclBit());
} }
} }

View File

@ -280,7 +280,7 @@ public void write(DataOutput out) throws IOException {
out.writeLong(getBlockSize()); out.writeLong(getBlockSize());
out.writeLong(getModificationTime()); out.writeLong(getModificationTime());
out.writeLong(getAccessTime()); out.writeLong(getAccessTime());
getPermission().write(out); out.writeShort(getPermission().toShort());
Text.writeString(out, getOwner(), Text.DEFAULT_MAX_LEN); Text.writeString(out, getOwner(), Text.DEFAULT_MAX_LEN);
Text.writeString(out, getGroup(), Text.DEFAULT_MAX_LEN); Text.writeString(out, getGroup(), Text.DEFAULT_MAX_LEN);
if (aclEntries != null) { if (aclEntries != null) {
@ -330,7 +330,7 @@ public void readFields(DataInput in) throws IOException {
blocksize = in.readLong(); blocksize = in.readLong();
modificationTime = in.readLong(); modificationTime = in.readLong();
accessTime = in.readLong(); accessTime = in.readLong();
permission.readFields(in); permission.fromShort(in.readShort());
owner = Text.readString(in, Text.DEFAULT_MAX_LEN); owner = Text.readString(in, Text.DEFAULT_MAX_LEN);
group = Text.readString(in, Text.DEFAULT_MAX_LEN); group = Text.readString(in, Text.DEFAULT_MAX_LEN);
byte aclEntriesSize = in.readByte(); byte aclEntriesSize = in.readByte();

View File

@ -31,7 +31,6 @@
import org.apache.hadoop.fs.XAttr; import org.apache.hadoop.fs.XAttr;
import org.apache.hadoop.fs.permission.AclEntry; import org.apache.hadoop.fs.permission.AclEntry;
import org.apache.hadoop.fs.permission.AclUtil; import org.apache.hadoop.fs.permission.AclUtil;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.io.SequenceFile; import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Text;
@ -403,8 +402,7 @@ public static CopyListingFileStatus toCopyListingFileStatusHelper(
CopyListingFileStatus copyListingFileStatus = CopyListingFileStatus copyListingFileStatus =
new CopyListingFileStatus(fileStatus, chunkOffset, chunkLength); new CopyListingFileStatus(fileStatus, chunkOffset, chunkLength);
if (preserveAcls) { if (preserveAcls) {
FsPermission perm = fileStatus.getPermission(); if (fileStatus.hasAcl()) {
if (perm.getAclBit()) {
List<AclEntry> aclEntries = fileSystem.getAclStatus( List<AclEntry> aclEntries = fileSystem.getAclStatus(
fileStatus.getPath()).getEntries(); fileStatus.getPath()).getEntries();
copyListingFileStatus.setAclEntries(aclEntries); copyListingFileStatus.setAclEntries(aclEntries);