HDFS-12250. Reduce usage of FsPermissionExtension in unit tests. Contributed by Chris Douglas.
This commit is contained in:
parent
f9a0e23381
commit
dd7916d3cd
@ -163,7 +163,7 @@ public FsPermission getUnmasked() {
|
||||
*/
|
||||
public static FsPermission read(DataInput in) throws IOException {
|
||||
FsPermission p = new FsPermission();
|
||||
p.readFields(in);
|
||||
p.fromShort(in.readShort());
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -86,9 +86,9 @@ protected void processPath(PathData item) throws IOException {
|
||||
(perm.getOtherAction().implies(FsAction.EXECUTE) ? "t" : "T"));
|
||||
}
|
||||
|
||||
AclStatus aclStatus = null;
|
||||
List<AclEntry> entries = null;
|
||||
if (perm.getAclBit()) {
|
||||
final AclStatus aclStatus;
|
||||
final List<AclEntry> entries;
|
||||
if (item.stat.hasAcl()) {
|
||||
aclStatus = item.fs.getAclStatus(item.path);
|
||||
entries = aclStatus.getEntries();
|
||||
} else {
|
||||
|
@ -444,8 +444,8 @@ protected void preserveAttributes(PathData src, PathData target,
|
||||
src.stat.getPermission());
|
||||
}
|
||||
if (shouldPreserve(FileAttribute.ACL)) {
|
||||
FsPermission perm = src.stat.getPermission();
|
||||
if (perm.getAclBit()) {
|
||||
if (src.stat.hasAcl()) {
|
||||
FsPermission perm = src.stat.getPermission();
|
||||
List<AclEntry> srcEntries =
|
||||
src.fs.getAclStatus(src.path).getEntries();
|
||||
List<AclEntry> srcFullEntries =
|
||||
|
@ -255,7 +255,7 @@ protected void processPath(PathData item) throws IOException {
|
||||
ContentSummary contentSummary = item.fs.getContentSummary(item.path);
|
||||
String line = String.format(lineFormat,
|
||||
(stat.isDirectory() ? "d" : "-"),
|
||||
stat.getPermission() + (stat.getPermission().getAclBit() ? "+" : " "),
|
||||
stat.getPermission() + (stat.hasAcl() ? "+" : " "),
|
||||
(stat.isFile() ? stat.getReplication() : "-"),
|
||||
stat.getOwner(),
|
||||
stat.getGroup(),
|
||||
@ -269,7 +269,7 @@ protected void processPath(PathData item) throws IOException {
|
||||
} else {
|
||||
String line = String.format(lineFormat,
|
||||
(stat.isDirectory() ? "d" : "-"),
|
||||
stat.getPermission() + (stat.getPermission().getAclBit() ? "+" : " "),
|
||||
stat.getPermission() + (stat.hasAcl() ? "+" : " "),
|
||||
(stat.isFile() ? stat.getReplication() : "-"),
|
||||
stat.getOwner(),
|
||||
stat.getGroup(),
|
||||
|
@ -859,6 +859,7 @@ private static void assertSameAcls(FileSystem expected, FileSystem actual,
|
||||
FileStatus expectedFileStatus = expected.getFileStatus(path);
|
||||
FileStatus actualFileStatus = actual.getFileStatus(path);
|
||||
assertEquals(actualFileStatus.hasAcl(), expectedFileStatus.hasAcl());
|
||||
// backwards compat
|
||||
assertEquals(actualFileStatus.getPermission().getAclBit(),
|
||||
expectedFileStatus.getPermission().getAclBit());
|
||||
}
|
||||
|
@ -2189,7 +2189,7 @@ public void testCopyCommandsWithPreserveOption() throws Exception {
|
||||
assertTrue(xattrs.isEmpty());
|
||||
List<AclEntry> acls = dfs.getAclStatus(target1).getEntries();
|
||||
assertTrue(acls.isEmpty());
|
||||
assertFalse(targetPerm.getAclBit());
|
||||
assertFalse(targetStatus.hasAcl());
|
||||
|
||||
// -ptop
|
||||
Path target2 = new Path(hdfsTestDir, "targetfile2");
|
||||
@ -2208,7 +2208,7 @@ public void testCopyCommandsWithPreserveOption() throws Exception {
|
||||
assertTrue(xattrs.isEmpty());
|
||||
acls = dfs.getAclStatus(target2).getEntries();
|
||||
assertTrue(acls.isEmpty());
|
||||
assertFalse(targetPerm.getAclBit());
|
||||
assertFalse(targetStatus.hasAcl());
|
||||
|
||||
// -ptopx
|
||||
Path target3 = new Path(hdfsTestDir, "targetfile3");
|
||||
@ -2229,7 +2229,7 @@ public void testCopyCommandsWithPreserveOption() throws Exception {
|
||||
assertArrayEquals(TRUSTED_A1_VALUE, xattrs.get(TRUSTED_A1));
|
||||
acls = dfs.getAclStatus(target3).getEntries();
|
||||
assertTrue(acls.isEmpty());
|
||||
assertFalse(targetPerm.getAclBit());
|
||||
assertFalse(targetStatus.hasAcl());
|
||||
|
||||
// -ptopa
|
||||
Path target4 = new Path(hdfsTestDir, "targetfile4");
|
||||
@ -2248,7 +2248,7 @@ public void testCopyCommandsWithPreserveOption() throws Exception {
|
||||
assertTrue(xattrs.isEmpty());
|
||||
acls = dfs.getAclStatus(target4).getEntries();
|
||||
assertFalse(acls.isEmpty());
|
||||
assertTrue(targetPerm.getAclBit());
|
||||
assertTrue(targetStatus.hasAcl());
|
||||
assertEquals(dfs.getAclStatus(src), dfs.getAclStatus(target4));
|
||||
|
||||
// -ptoa (verify -pa option will preserve permissions also)
|
||||
@ -2268,7 +2268,7 @@ public void testCopyCommandsWithPreserveOption() throws Exception {
|
||||
assertTrue(xattrs.isEmpty());
|
||||
acls = dfs.getAclStatus(target5).getEntries();
|
||||
assertFalse(acls.isEmpty());
|
||||
assertTrue(targetPerm.getAclBit());
|
||||
assertTrue(targetStatus.hasAcl());
|
||||
assertEquals(dfs.getAclStatus(src), dfs.getAclStatus(target5));
|
||||
} finally {
|
||||
if (null != shell) {
|
||||
@ -2480,7 +2480,7 @@ public void testCopyCommandsToDirectoryWithPreserveOption()
|
||||
assertTrue(xattrs.isEmpty());
|
||||
List<AclEntry> acls = dfs.getAclStatus(targetDir1).getEntries();
|
||||
assertTrue(acls.isEmpty());
|
||||
assertFalse(targetPerm.getAclBit());
|
||||
assertFalse(targetStatus.hasAcl());
|
||||
|
||||
// -ptop
|
||||
Path targetDir2 = new Path(hdfsTestDir, "targetDir2");
|
||||
@ -2499,7 +2499,7 @@ public void testCopyCommandsToDirectoryWithPreserveOption()
|
||||
assertTrue(xattrs.isEmpty());
|
||||
acls = dfs.getAclStatus(targetDir2).getEntries();
|
||||
assertTrue(acls.isEmpty());
|
||||
assertFalse(targetPerm.getAclBit());
|
||||
assertFalse(targetStatus.hasAcl());
|
||||
|
||||
// -ptopx
|
||||
Path targetDir3 = new Path(hdfsTestDir, "targetDir3");
|
||||
@ -2520,7 +2520,7 @@ public void testCopyCommandsToDirectoryWithPreserveOption()
|
||||
assertArrayEquals(TRUSTED_A1_VALUE, xattrs.get(TRUSTED_A1));
|
||||
acls = dfs.getAclStatus(targetDir3).getEntries();
|
||||
assertTrue(acls.isEmpty());
|
||||
assertFalse(targetPerm.getAclBit());
|
||||
assertFalse(targetStatus.hasAcl());
|
||||
|
||||
// -ptopa
|
||||
Path targetDir4 = new Path(hdfsTestDir, "targetDir4");
|
||||
@ -2539,7 +2539,7 @@ public void testCopyCommandsToDirectoryWithPreserveOption()
|
||||
assertTrue(xattrs.isEmpty());
|
||||
acls = dfs.getAclStatus(targetDir4).getEntries();
|
||||
assertFalse(acls.isEmpty());
|
||||
assertTrue(targetPerm.getAclBit());
|
||||
assertTrue(targetStatus.hasAcl());
|
||||
assertEquals(dfs.getAclStatus(srcDir), dfs.getAclStatus(targetDir4));
|
||||
|
||||
// -ptoa (verify -pa option will preserve permissions also)
|
||||
@ -2559,7 +2559,7 @@ public void testCopyCommandsToDirectoryWithPreserveOption()
|
||||
assertTrue(xattrs.isEmpty());
|
||||
acls = dfs.getAclStatus(targetDir5).getEntries();
|
||||
assertFalse(acls.isEmpty());
|
||||
assertTrue(targetPerm.getAclBit());
|
||||
assertTrue(targetStatus.hasAcl());
|
||||
assertEquals(dfs.getAclStatus(srcDir), dfs.getAclStatus(targetDir5));
|
||||
} finally {
|
||||
if (shell != null) {
|
||||
@ -2615,7 +2615,7 @@ public void testCopyCommandsPreserveAclAndStickyBit() throws Exception {
|
||||
assertTrue(perm.equals(targetPerm));
|
||||
List<AclEntry> acls = dfs.getAclStatus(target1).getEntries();
|
||||
assertTrue(acls.isEmpty());
|
||||
assertFalse(targetPerm.getAclBit());
|
||||
assertFalse(targetStatus.hasAcl());
|
||||
|
||||
// -ptopa preserves both sticky bit and ACL
|
||||
Path target2 = new Path(hdfsTestDir, "targetfile2");
|
||||
@ -2632,7 +2632,7 @@ public void testCopyCommandsPreserveAclAndStickyBit() throws Exception {
|
||||
assertTrue(perm.equals(targetPerm));
|
||||
acls = dfs.getAclStatus(target2).getEntries();
|
||||
assertFalse(acls.isEmpty());
|
||||
assertTrue(targetPerm.getAclBit());
|
||||
assertTrue(targetStatus.hasAcl());
|
||||
assertEquals(dfs.getAclStatus(src), dfs.getAclStatus(target2));
|
||||
} finally {
|
||||
if (null != shell) {
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
||||
import org.apache.hadoop.fs.FileStatus;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.fs.permission.AclEntry;
|
||||
@ -886,6 +887,11 @@ public void testSetPermissionCannotSetAclBit() throws IOException {
|
||||
FsPermission perm = inode.getFsPermission();
|
||||
assertNotNull(perm);
|
||||
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());
|
||||
assertAclFeature(false);
|
||||
}
|
||||
|
@ -28,7 +28,6 @@
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
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.security.TokenCache;
|
||||
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,
|
||||
FsAction action, Map<URI, FileStatus> statCache) throws IOException {
|
||||
FileStatus status = getFileStatus(fs, path.toUri(), statCache);
|
||||
FsPermission perms = status.getPermission();
|
||||
|
||||
// Encrypted files are always treated as private. This stance has two
|
||||
// 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
|
||||
// being localized as a publicly shared file with world readable
|
||||
// permissions.
|
||||
if (!perms.getEncryptedBit()) {
|
||||
FsAction otherAction = perms.getOtherAction();
|
||||
if (!status.isEncrypted()) {
|
||||
FsAction otherAction = status.getPermission().getOtherAction();
|
||||
if (otherAction.implies(action)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -98,4 +98,5 @@ public void getFileStatusAclBit() throws URISyntaxException, IOException {
|
||||
Assert.assertFalse(fileStatus.hasAcl());
|
||||
Assert.assertFalse(fileStatus.getPermission().getAclBit());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ public void write(DataOutput out) throws IOException {
|
||||
out.writeLong(getBlockSize());
|
||||
out.writeLong(getModificationTime());
|
||||
out.writeLong(getAccessTime());
|
||||
getPermission().write(out);
|
||||
out.writeShort(getPermission().toShort());
|
||||
Text.writeString(out, getOwner(), Text.DEFAULT_MAX_LEN);
|
||||
Text.writeString(out, getGroup(), Text.DEFAULT_MAX_LEN);
|
||||
if (aclEntries != null) {
|
||||
@ -330,7 +330,7 @@ public void readFields(DataInput in) throws IOException {
|
||||
blocksize = in.readLong();
|
||||
modificationTime = in.readLong();
|
||||
accessTime = in.readLong();
|
||||
permission.readFields(in);
|
||||
permission.fromShort(in.readShort());
|
||||
owner = Text.readString(in, Text.DEFAULT_MAX_LEN);
|
||||
group = Text.readString(in, Text.DEFAULT_MAX_LEN);
|
||||
byte aclEntriesSize = in.readByte();
|
||||
|
@ -31,7 +31,6 @@
|
||||
import org.apache.hadoop.fs.XAttr;
|
||||
import org.apache.hadoop.fs.permission.AclEntry;
|
||||
import org.apache.hadoop.fs.permission.AclUtil;
|
||||
import org.apache.hadoop.fs.permission.FsPermission;
|
||||
import org.apache.hadoop.hdfs.DistributedFileSystem;
|
||||
import org.apache.hadoop.io.SequenceFile;
|
||||
import org.apache.hadoop.io.Text;
|
||||
@ -403,8 +402,7 @@ public static CopyListingFileStatus toCopyListingFileStatusHelper(
|
||||
CopyListingFileStatus copyListingFileStatus =
|
||||
new CopyListingFileStatus(fileStatus, chunkOffset, chunkLength);
|
||||
if (preserveAcls) {
|
||||
FsPermission perm = fileStatus.getPermission();
|
||||
if (perm.getAclBit()) {
|
||||
if (fileStatus.hasAcl()) {
|
||||
List<AclEntry> aclEntries = fileSystem.getAclStatus(
|
||||
fileStatus.getPath()).getEntries();
|
||||
copyListingFileStatus.setAclEntries(aclEntries);
|
||||
|
Loading…
Reference in New Issue
Block a user