boolean ownerOrGroupChanged = false; if (username != null && !username.isEmpty()) { optionsBuilder.setOwner(username).setRecursive(false); ownerOrGroupChanged = true; optionsBuilder.setGroup(groupname).setRecursive(false); ownerOrGroupChanged = true;
/** * Changes the owner for the path specified in args. * * @param path The {@link AlluxioURI} path as the input of the command * @param owner The owner to be updated to the file or directory * @param recursive Whether change the owner recursively */ private void chown(AlluxioURI path, String owner, boolean recursive) throws AlluxioException, IOException { SetAttributePOptions options = SetAttributePOptions.newBuilder().setOwner(owner).setRecursive(recursive).build(); mFileSystem.setAttribute(path, options); System.out.println("Changed owner of " + path + " to " + owner); }
/** * 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); }
.defaults(SetAttributePOptions.newBuilder().setRecursive(false).setPinned(false)); setAttributeSingleFile(rpcContext, descedant, true, opTimeMs, setAttributeContext);
setRecursive(other.getRecursive());
private void verifySetAcl(TestUser runUser, String path, String owner, String group, short mode, boolean recursive) throws Exception { try (Closeable r = new AuthenticatedUserRule(runUser.getUser(), ServerConfiguration.global()).toResource()) { SetAttributeContext context = SetAttributeContext.defaults(SetAttributePOptions.newBuilder() .setMode(new Mode(mode).toProto()).setRecursive(recursive)); if (owner != null) { context.getOptions().setOwner(owner); } if (group != null) { context.getOptions().setGroup(group); } mFileSystemMaster.setAttribute(new AlluxioURI(path), context); } try (Closeable r = new AuthenticatedUserRule(TEST_USER_ADMIN.getUser(), ServerConfiguration.global()).toResource()) { FileInfo fileInfo = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(path))); if (owner != null) { assertEquals(owner, fileInfo.getOwner()); } if (group != null) { assertEquals(group, fileInfo.getGroup()); } if (mode != -1) { assertEquals(mode, fileInfo.getMode()); } } }
/** * Changes the replication level of directory or file with the path specified in args. * * @param path The {@link AlluxioURI} path as the input of the command * @param replicationMax the max replicas, null if not to set * @param replicationMin the min replicas, null if not to set * @param recursive Whether change the permission recursively * @throws AlluxioException when Alluxio exception occurs * @throws IOException when non-Alluxio exception occurs */ private void setReplication(AlluxioURI path, Integer replicationMax, Integer replicationMin, boolean recursive) throws AlluxioException, IOException { SetAttributePOptions.Builder optionsBuilder = SetAttributePOptions.newBuilder().setRecursive(recursive); String message = "Changed the replication level of " + path + "\n"; if (replicationMax != null) { optionsBuilder.setReplicationMax(replicationMax); message += "replicationMax was set to " + replicationMax + "\n"; } if (replicationMin != null) { optionsBuilder.setReplicationMin(replicationMin); message += "replicationMin was set to " + replicationMin + "\n"; } mFileSystem.setAttribute(path, optionsBuilder.build()); System.out.println(message); }
@Test public void listStatusRecursivePermissions() throws Exception { final int files = 10; List<FileInfo> infos; List<String> filenames; // Test files in root directory. for (int i = 0; i < files; i++) { createFileWithSingleBlock(ROOT_URI.join("file" + String.format("%05d", i))); } // Test files in nested directory. for (int i = 0; i < files; i++) { createFileWithSingleBlock(NESTED_URI.join("file" + String.format("%05d", i))); } // Test with permissions mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.defaults(SetAttributePOptions .newBuilder().setMode(new Mode((short) 0400).toProto()).setRecursive(true))); try (Closeable r = new AuthenticatedUserRule("test_user1", ServerConfiguration.global()) .toResource()) { // Test recursive listStatus infos = mFileSystemMaster.listStatus(ROOT_URI, ListStatusContext.defaults(ListStatusPOptions .newBuilder().setLoadMetadataType(LoadMetadataPType.ALWAYS).setRecursive(true))); // 10 files in each directory, 1 level of directories assertEquals(files + 1, infos.size()); } }
/** * Changes permission of a path. * * @param path path to set permission * @param permission permission set to path */ @Override public void setPermission(Path path, FsPermission permission) throws IOException { LOG.debug("setMode({},{})", path, permission.toString()); AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); SetAttributePOptions options = SetAttributePOptions.newBuilder() .setMode(new Mode(permission.toShort()).toProto()).setRecursive(false).build(); try { mFileSystem.setAttribute(uri, options); } catch (AlluxioException e) { throw new IOException(e); } }
/** * Sets a new TTL value or unsets an existing TTL value for file at path. * * @param fs the file system for Alluxio * @param path the file path * @param ttlMs the TTL (time to live) value to use; it identifies duration (in milliseconds) the * created file should be kept around before it is automatically deleted, irrespective of * whether the file is pinned; {@link Constants#NO_TTL} means to unset the TTL value * @param ttlAction Action to perform on Ttl expiry */ public static void setTtl(FileSystem fs, AlluxioURI path, long ttlMs, TtlAction ttlAction) throws AlluxioException, IOException { SetAttributePOptions options = SetAttributePOptions.newBuilder().setRecursive(true) .setTtl(ttlMs).setTtlAction(ttlAction).build(); fs.setAttribute(path, options); }
/** * Changes the permissions of directory or file with the path specified in args. * * @param path The {@link AlluxioURI} path as the input of the command * @param modeStr The new permission to be updated to the file or directory * @param recursive Whether change the permission recursively */ private void chmod(AlluxioURI path, String modeStr, boolean recursive) throws AlluxioException, IOException { Mode mode = ModeParser.parse(modeStr); SetAttributePOptions options = SetAttributePOptions.newBuilder().setMode(mode.toProto()).setRecursive(recursive).build(); mFileSystem.setAttribute(path, options); System.out .println("Changed permission of " + path + " to " + Integer.toOctalString(mode.toShort())); }
/** * 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 + "."); }
/** * @return Master side defaults for {@link SetAttributePOptions} */ public static SetAttributePOptions setAttributesDefaults() { return SetAttributePOptions.newBuilder() .setCommonOptions(commonDefaults()) .setTtlAction(TtlAction.DELETE) .setRecursive(false) .build(); }