Path dirToMake = dirsToMake.pop(); if (!FileSystem.mkdirs(hdfs, dirToMake, new FsPermission(options.getMode().toShort()))) { return false;
if (!options.getCreateParent()) { if (file.mkdir()) { setMode(file.getPath(), options.getMode().toShort()); FileUtils.setLocalDirStickyBit(file.getPath()); try { File dirToMake = dirsToMake.pop(); if (dirToMake.mkdir()) { setMode(dirToMake.getAbsolutePath(), options.getMode().toShort()); FileUtils.setLocalDirStickyBit(file.getPath());
/** * Tests getting and setting fields. */ @Test public void fields() { Random random = new Random(); boolean createParent = random.nextBoolean(); String owner = CommonUtils.randomAlphaNumString(10); String group = CommonUtils.randomAlphaNumString(10); Mode mode = new Mode((short) random.nextInt()); MkdirsOptions options = MkdirsOptions.defaults(mConfiguration); options.setCreateParent(createParent); options.setOwner(owner); options.setGroup(group); options.setMode(mode); assertEquals(createParent, options.getCreateParent()); assertEquals(owner, options.getOwner()); assertEquals(group, options.getGroup()); assertEquals(mode, options.getMode()); }
/** * Tests for default {@link MkdirsOptions}. */ @Test public void defaults() throws IOException { MkdirsOptions options = MkdirsOptions.defaults(mConfiguration); // Verify the default createParent is true. assertTrue(options.getCreateParent()); // Verify that the owner and group are not set. assertNull(options.getOwner()); assertNull(options.getGroup()); String umask = mConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK); assertEquals(ModeUtils.applyDirectoryUMask(Mode.defaults(), umask), options.getMode()); }
/** * Tests for building an {@link MkdirsOptions} with a security enabled * configuration. */ @Test public void securityEnabled() throws IOException { InstancedConfiguration conf = new InstancedConfiguration(ConfigurationUtils.defaults()); conf.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE.getAuthName()); conf.set(PropertyKey.SECURITY_LOGIN_USERNAME, "foo"); // Use IdentityUserGroupMapping to map user "foo" to group "foo". conf.set(PropertyKey.SECURITY_GROUP_MAPPING_CLASS, IdentityUserGroupsMapping.class.getName()); MkdirsOptions options = MkdirsOptions.defaults(mConfiguration); // Verify the default createParent is true. assertTrue(options.getCreateParent()); // Verify that the owner and group are not set. assertNull(options.getOwner()); assertNull(options.getGroup()); String umask = mConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK); assertEquals(ModeUtils.applyDirectoryUMask(Mode.defaults(), umask), options.getMode()); }
Path dirToMake = dirsToMake.pop(); if (!FileSystem.mkdirs(mFileSystem, dirToMake, new FsPermission(options.getMode().toShort()))) { return false;