use of alluxio.jnifuse.struct.FuseContext in project alluxio by Alluxio.
the class SystemUserGroupAuthPolicy method setUserGroupIfNeeded.
@Override
public void setUserGroupIfNeeded(AlluxioURI uri) throws Exception {
FuseContext fc = mFuseFileSystem.getContext();
if (!mIsUserGroupTranslation) {
return;
}
long uid = fc.uid.get();
long gid = fc.gid.get();
if (uid == AlluxioFuseUtils.ID_NOT_SET_VALUE || uid == AlluxioFuseUtils.ID_NOT_SET_VALUE_UNSIGNED || gid == AlluxioFuseUtils.ID_NOT_SET_VALUE || gid == AlluxioFuseUtils.ID_NOT_SET_VALUE_UNSIGNED) {
// cannot get valid uid or gid
return;
}
if (uid == AlluxioFuseUtils.DEFAULT_UID && gid == AlluxioFuseUtils.DEFAULT_GID) {
// no need to set attribute
return;
}
String groupName = gid != AlluxioFuseUtils.DEFAULT_GID ? mGroupnameCache.get(gid) : AlluxioFuseUtils.DEFAULT_GROUP_NAME;
String userName = uid != AlluxioFuseUtils.DEFAULT_UID ? mUsernameCache.get(uid) : AlluxioFuseUtils.DEFAULT_USER_NAME;
if (userName.isEmpty() || groupName.isEmpty()) {
// cannot get valid user name and group name
return;
}
SetAttributePOptions attributeOptions = SetAttributePOptions.newBuilder().setGroup(groupName).setOwner(userName).build();
LOG.debug("Set attributes of path {} to {}", uri, attributeOptions);
mFileSystem.setAttribute(uri, attributeOptions);
}
Aggregations