本文整理了Java中alluxio.security.authorization.Mode
类的一些代码示例,展示了Mode
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mode
类的具体详情如下:
包路径:alluxio.security.authorization.Mode
类名称:Mode
[英]POSIX style file/directory access mode.
[中]POSIX风格的文件/目录访问模式。
代码示例来源:origin: Alluxio/alluxio
/**
* Changes the mode of an Alluxio file.
*
* @param path the path of the file
* @param mode the mode to change to
* @return 0 on success, a negative value on error
*/
@Override
public int chmod(String path, @mode_t long mode) {
AlluxioURI uri = mPathResolverCache.getUnchecked(path);
SetAttributePOptions options = SetAttributePOptions.newBuilder()
.setMode(new alluxio.security.authorization.Mode((short) mode).toProto()).build();
try {
mFileSystem.setAttribute(uri, options);
} catch (Throwable t) {
LOG.error("Failed to change {} to mode {}", path, mode, t);
return AlluxioFuseUtils.getErrorCode(t);
}
return 0;
}
代码示例来源:origin: Alluxio/alluxio
/**
* Tests the {@link Mode#Mode(Mode)} constructor.
*/
@Test
public void copyConstructor() {
Mode mode = new Mode(Mode.defaults());
assertEquals(Mode.Bits.ALL, mode.getOwnerBits());
assertEquals(Mode.Bits.ALL, mode.getGroupBits());
assertEquals(Mode.Bits.ALL, mode.getOtherBits());
assertEquals(0777, mode.toShort());
}
代码示例来源:origin: Alluxio/alluxio
return;
case OWNING_USER:
Mode modeOwner = new Mode(mMode);
modeOwner.setOwnerBits(Mode.Bits.NONE);
if (mAccessAcl != null) {
modeOwner.setOwnerBits(new Mode(mAccessAcl.mMode).getOwnerBits());
mMode = modeOwner.toShort();
return;
case OWNING_GROUP:
Mode modeGroup = new Mode(mMode);
modeGroup.setGroupBits(Mode.Bits.NONE);
if (mAccessAcl != null) {
modeGroup.setGroupBits(new Mode(mAccessAcl.mMode).getGroupBits());
mMode = modeGroup.toShort();
return;
case OTHER:
Mode modeOther = new Mode(mMode);
modeOther.setOtherBits(Mode.Bits.NONE);
if (mAccessAcl != null) {
modeOther.setOtherBits(new Mode(mAccessAcl.mMode).getOtherBits());
mMode = modeOther.toShort();
return;
default:
代码示例来源:origin: Alluxio/alluxio
/**
* Used to get short value of a proto {@link PMode}.
*
* @param pMode proto mode
* @return short value
*/
public static short protoToShort(PMode pMode) {
return Mode.fromProto(pMode).toShort();
}
代码示例来源:origin: Alluxio/alluxio
/**
* Applies the given umask {@link Mode} to this mode.
*
* @param mode the mode to update
* @param umask the umask to apply
* @return the updated object
*/
private static Mode applyUMask(Mode mode, Mode umask) {
mode.setOwnerBits(mode.getOwnerBits().and(umask.getOwnerBits().not()));
mode.setGroupBits(mode.getGroupBits().and(umask.getGroupBits().not()));
mode.setOtherBits(mode.getOtherBits().and(umask.getOtherBits().not()));
return mode;
}
代码示例来源:origin: Alluxio/alluxio
short ufsMode = context.getUfsStatus().getMode();
Long lastModifiedTime = context.getUfsStatus().getLastModifiedTime();
Mode mode = new Mode(ufsMode);
if (resolution.getShared()) {
mode.setOtherBits(mode.getOtherBits().or(mode.getOwnerBits()));
createDirectoryContext.getOptions().setMode(mode.toProto());
createDirectoryContext.setOwner(ufsOwner).setGroup(ufsGroup)
.setUfsStatus(context.getUfsStatus());
代码示例来源:origin: Alluxio/alluxio
Mode defaultMode = new Mode(umask);
AccessControlList acl = new AccessControlList();
acl.mOwningUser = mOwningUser;
acl.mExtendedEntries = null;
acl.mMode = Mode.and(new Mode(mMode), defaultMode).toShort();
} else {
groupAction.updateByModeBits(defaultMode.getGroupBits());
mask.mask(groupAction);
Mode updateMode = new Mode(mMode);
updateMode.setOwnerBits(updateMode.getOwnerBits().and(defaultMode.getOwnerBits()));
updateMode.setOtherBits(updateMode.getOtherBits().and(defaultMode.getOtherBits()));
acl.mMode = updateMode.toShort();
代码示例来源:origin: Alluxio/alluxio
/**
* Gets the default mode.
*
* @return the default {@link Mode}
*/
public static Mode defaults() {
return new Mode(Constants.DEFAULT_FILE_SYSTEM_MODE);
}
代码示例来源:origin: Alluxio/alluxio
/**
* Formats digital representation of a model as a human-readable string.
*
* @param mode file mode
* @param directory if the mode corresponds to a directory
* @param hasExtended true if extended acls exist
* @return human-readable version of the given mode
*/
public static String formatMode(short mode, boolean directory, boolean hasExtended) {
StringBuilder str = new StringBuilder();
if (directory) {
str.append("d");
} else {
str.append("-");
}
str.append(new Mode(mode).toString());
if (hasExtended) {
str.append("+");
}
return str.toString();
}
代码示例来源:origin: Alluxio/alluxio
return;
case OWNING_USER:
Mode modeOwner = new Mode(mMode);
modeOwner.setOwnerBits(entry.getActions().toModeBits());
mMode = modeOwner.toShort();
return;
case OWNING_GROUP:
Mode modeGroup = new Mode(mMode);
modeGroup.setGroupBits(entry.getActions().toModeBits());
mMode = modeGroup.toShort();
return;
case OTHER:
Mode modeOther = new Mode(mMode);
modeOther.setOtherBits(entry.getActions().toModeBits());
mMode = modeOther.toShort();
return;
default:
代码示例来源:origin: Alluxio/alluxio
@Override
public int hashCode() {
return toShort();
}
代码示例来源:origin: Alluxio/alluxio
@Test
public void numerics() {
Mode parsed = ModeParser.parse("777");
Assert.assertEquals(Mode.Bits.ALL, parsed.getOwnerBits());
Assert.assertEquals(Mode.Bits.ALL, parsed.getGroupBits());
Assert.assertEquals(Mode.Bits.ALL, parsed.getOtherBits());
parsed = ModeParser.parse("755");
Assert.assertEquals(Mode.Bits.ALL, parsed.getOwnerBits());
Assert.assertEquals(Mode.Bits.READ_EXECUTE, parsed.getGroupBits());
Assert.assertEquals(Mode.Bits.READ_EXECUTE, parsed.getOtherBits());
parsed = ModeParser.parse("644");
Assert.assertEquals(Mode.Bits.READ_WRITE, parsed.getOwnerBits());
Assert.assertEquals(Mode.Bits.READ, parsed.getGroupBits());
Assert.assertEquals(Mode.Bits.READ, parsed.getOtherBits());
}
代码示例来源:origin: Alluxio/alluxio
/**
* Tests the {@link Mode#toShort()} method.
*/
@Test
public void toShort() {
Mode mode = new Mode(Mode.Bits.ALL, Mode.Bits.READ_EXECUTE, Mode.Bits.READ_EXECUTE);
assertEquals(0755, mode.toShort());
mode = Mode.defaults();
assertEquals(0777, mode.toShort());
mode = new Mode(Mode.Bits.READ_WRITE, Mode.Bits.READ, Mode.Bits.READ);
assertEquals(0644, mode.toShort());
}
代码示例来源:origin: Alluxio/alluxio
/**
* Tests {@link AccessControlList#setMode(short)}.
*/
@Test
public void setMode() {
AccessControlList acl = new AccessControlList();
short mode = new Mode(Mode.Bits.EXECUTE, Mode.Bits.WRITE, Mode.Bits.READ).toShort();
acl.setMode(mode);
Assert.assertEquals(mode, acl.getMode());
}
代码示例来源:origin: Alluxio/alluxio
/**
* Tests the {@link Mode#createNoAccess()} method.
*/
@Test
public void createNoAccess() {
Mode mode = Mode.createNoAccess();
assertEquals(Mode.Bits.NONE, mode.getOwnerBits());
assertEquals(Mode.Bits.NONE, mode.getGroupBits());
assertEquals(Mode.Bits.NONE, mode.getOtherBits());
assertEquals(0000, mode.toShort());
}
代码示例来源:origin: Alluxio/alluxio
/**
* Tests the {@link Mode#fromShort(short)} method.
*/
@Test
public void fromShort() {
Mode mode = new Mode((short) 0777);
assertEquals(Mode.Bits.ALL, mode.getOwnerBits());
assertEquals(Mode.Bits.ALL, mode.getGroupBits());
assertEquals(Mode.Bits.ALL, mode.getOtherBits());
mode = new Mode((short) 0644);
assertEquals(Mode.Bits.READ_WRITE, mode.getOwnerBits());
assertEquals(Mode.Bits.READ, mode.getGroupBits());
assertEquals(Mode.Bits.READ, mode.getOtherBits());
mode = new Mode((short) 0755);
assertEquals(Mode.Bits.ALL, mode.getOwnerBits());
assertEquals(Mode.Bits.READ_EXECUTE, mode.getGroupBits());
assertEquals(Mode.Bits.READ_EXECUTE, mode.getOtherBits());
}
代码示例来源:origin: Alluxio/alluxio
@Test
public void defaults() {
Mode mode = Mode.defaults();
assertEquals(Constants.DEFAULT_FILE_SYSTEM_MODE, mode.toShort());
}
代码示例来源:origin: Alluxio/alluxio
/**
* Tests the {@link Mode#equals(Object)} method.
*/
@Test
public void equals() {
Mode allAccess = new Mode((short) 0777);
assertTrue(allAccess.equals(Mode.defaults()));
Mode noAccess = new Mode((short) 0000);
assertTrue(noAccess.equals(Mode.createNoAccess()));
assertFalse(allAccess.equals(noAccess));
}
代码示例来源:origin: Alluxio/alluxio
@Test
public void setOtherBits() {
Mode mode = new Mode((short) 0000);
mode.setOtherBits(Mode.Bits.READ_EXECUTE);
assertEquals(Mode.Bits.READ_EXECUTE, mode.getOtherBits());
mode.setOtherBits(Mode.Bits.WRITE);
assertEquals(Mode.Bits.WRITE, mode.getOtherBits());
mode.setOtherBits(Mode.Bits.ALL);
assertEquals(Mode.Bits.ALL, mode.getOtherBits());
}
}
代码示例来源:origin: Alluxio/alluxio
@Test
public void setOwnerBits() {
Mode mode = new Mode((short) 0000);
mode.setOwnerBits(Mode.Bits.READ_EXECUTE);
assertEquals(Mode.Bits.READ_EXECUTE, mode.getOwnerBits());
mode.setOwnerBits(Mode.Bits.WRITE);
assertEquals(Mode.Bits.WRITE, mode.getOwnerBits());
mode.setOwnerBits(Mode.Bits.ALL);
assertEquals(Mode.Bits.ALL, mode.getOwnerBits());
}
内容来源于网络,如有侵权,请联系作者删除!