use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.
the class ChownCommand method chown.
/**
* Changes the owner and group for the path specified in args.
*
* @param path the {@link AlluxioURI} path to update
* @param owner the new owner
* @param group the new group
* @param recursive whether to change the owner and group recursively
*/
private void chown(AlluxioURI path, String owner, String group, boolean recursive) throws AlluxioException, IOException {
SetAttributePOptions options = SetAttributePOptions.newBuilder().setOwner(owner).setGroup(group).setRecursive(recursive).build();
mFileSystem.setAttribute(path, options);
System.out.println("Changed owner:group of " + path + " to " + owner + ":" + group + ".");
}
use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.
the class ChgrpCommand method chgrp.
/**
* Changes the group for the directory or file with the path specified in args.
*
* @param path The {@link AlluxioURI} path as the input of the command
* @param group The group to be updated to the file or directory
* @param recursive Whether change the group recursively
*/
private void chgrp(AlluxioURI path, String group, boolean recursive) throws AlluxioException, IOException {
SetAttributePOptions options = SetAttributePOptions.newBuilder().setGroup(group).setRecursive(recursive).build();
mFileSystem.setAttribute(path, options);
System.out.println("Changed group of " + path + " to " + group);
}
use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.
the class SetAttributeContext method mergeFrom.
/**
* Merges and embeds the given {@link SetAttributePOptions} with the corresponding master options.
*
* @param optionsBuilder Builder for proto {@link SetAttributePOptions} to merge with defaults
* @return the instance of {@link SetAttributeContext} with default values for master
*/
public static SetAttributeContext mergeFrom(SetAttributePOptions.Builder optionsBuilder) {
SetAttributePOptions masterOptions = FileSystemOptions.setAttributeDefaults(ServerConfiguration.global());
SetAttributePOptions.Builder mergedOptionsBuilder = masterOptions.toBuilder().mergeFrom(optionsBuilder.build());
return create(mergedOptionsBuilder);
}
use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method mkdirInternal.
private int mkdirInternal(String path, @mode_t long mode) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
if (turi.getName().length() > MAX_NAME_LENGTH) {
LOG.error("Failed to create directory {}, directory name is longer than {} characters", path, MAX_NAME_LENGTH);
return -ErrorCodes.ENAMETOOLONG();
}
SetAttributePOptions.Builder attributeOptionsBuilder = SetAttributePOptions.newBuilder();
FuseContext fc = getContext();
long uid = fc.uid.get();
long gid = fc.gid.get();
try {
if (gid != GID) {
String groupName = AlluxioFuseUtils.getGroupName(gid);
if (groupName.isEmpty()) {
// This should never be reached since input gid is always valid
LOG.error("Failed to get group name from gid {}.", gid);
return -ErrorCodes.EFAULT();
}
attributeOptionsBuilder.setGroup(groupName);
}
if (uid != UID) {
String userName = AlluxioFuseUtils.getUserName(uid);
if (userName.isEmpty()) {
// This should never be reached since input uid is always valid
LOG.error("Failed to get user name from uid {}", uid);
return -ErrorCodes.EFAULT();
}
attributeOptionsBuilder.setOwner(userName);
}
SetAttributePOptions setAttributePOptions = attributeOptionsBuilder.build();
mFileSystem.createDirectory(turi, CreateDirectoryPOptions.newBuilder().setMode(new alluxio.security.authorization.Mode((short) mode).toProto()).build());
if (gid != GID || uid != UID) {
LOG.debug("Set attributes of path {} to {}", path, setAttributePOptions);
mFileSystem.setAttribute(turi, setAttributePOptions);
}
} catch (FileAlreadyExistsException e) {
LOG.debug("Failed to create directory {}, directory already exists", path);
return -ErrorCodes.EEXIST();
} catch (InvalidPathException e) {
LOG.debug("Failed to create directory {}, path is invalid", path);
return -ErrorCodes.ENOENT();
} catch (Throwable t) {
LOG.error("Failed to create directory {}", path, t);
return AlluxioFuseUtils.getErrorCode(t);
}
return 0;
}
use of alluxio.grpc.SetAttributePOptions in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method chmodInternal.
private int chmodInternal(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;
}
Aggregations