@Override public void flush() throws IOException { super.flush(); if (LOG.isDebugEnabled()) { LOG.debug("Resetting permissions to '" + permissions + "'"); } if (!Shell.WINDOWS) { Files.setPosixFilePermissions(Paths.get(file.getCanonicalPath()), permissions); } else { // FsPermission expects a 10-character string because of the leading // directory indicator, i.e. "drwx------". The JDK toString method returns // a 9-character string, so prepend a leading character. FsPermission fsPermission = FsPermission.valueOf( "-" + PosixFilePermissions.toString(permissions)); FileUtil.setPermission(file, fsPermission); } }
private void assertFsPermissionTransformationIsGood(String perms) { Assert.assertEquals(perms, FsPermission.valueOf("-" + perms).toString()); }
FsPermission.MAX_PERMISSION_LENGTH); setPermission(FsPermission.valueOf(permission)); t.nextToken();
FsPermission perms = FsPermission.valueOf(permsStr);
private static void validatePermissions(CliSessionState ss, HiveConf conf, String perms) { perms = perms.trim(); FsPermission fp = null; if (perms.matches("^\\s*([r,w,x,-]{9})\\s*$")) { fp = FsPermission.valueOf("d" + perms); } else if (perms.matches("^\\s*([0-7]{3})\\s*$")) { fp = new FsPermission(Short.decode("0" + perms)); } else { ss.err.println("Invalid permission specification: " + perms); sysExit(ss,1); } if (!HCatUtil.validateMorePermissive(fp.getUserAction(), fp.getGroupAction())) { ss.err.println("Invalid permission specification: " + perms + " : user permissions must be more permissive than group permission "); sysExit(ss,1); } if (!HCatUtil.validateMorePermissive(fp.getGroupAction(), fp.getOtherAction())) { ss.err.println("Invalid permission specification: " + perms + " : group permissions must be more permissive than other permission "); sysExit(ss,1); } if ((!HCatUtil.validateExecuteBitPresentIfReadOrWrite(fp.getUserAction())) || (!HCatUtil.validateExecuteBitPresentIfReadOrWrite(fp.getGroupAction())) || (!HCatUtil.validateExecuteBitPresentIfReadOrWrite(fp.getOtherAction()))) { ss.err.println("Invalid permission specification: " + perms + " : permissions must have execute permissions if read or write permissions are specified "); sysExit(ss,1); } conf.set(HCatConstants.HCAT_PERMS, "d" + fp.toString()); }
assertEquals(ret, 0); dfsPath = clientWH.getDefaultTablePath(db, tblName); assertEquals(FsPermission.valueOf("drwx-wx---"), dfsPath.getFileSystem(hcatConf).getFileStatus(dfsPath).getPermission());
@Test public void testBulkLoadWithoutWritePermission() throws Exception { // Use the USER_CREATE to initialize the source directory. Path testDataDir0 = TEST_UTIL.getDataTestDirOnTestFS("testBulkLoadWithoutWritePermission0"); Path testDataDir1 = TEST_UTIL.getDataTestDirOnTestFS("testBulkLoadWithoutWritePermission1"); AccessTestAction bulkLoadAction1 = new BulkLoadAccessTestAction(FsPermission.valueOf("-r-xr-xr-x"), testDataDir0); AccessTestAction bulkLoadAction2 = new BulkLoadAccessTestAction(FS_PERMISSION_ALL, testDataDir1); // Test the incorrect case. BulkLoadHelper.setPermission(TEST_UTIL.getTestFileSystem(), TEST_UTIL.getTestFileSystem().getWorkingDirectory(), FS_PERMISSION_ALL); try { USER_CREATE.runAs(bulkLoadAction1); fail("Should fail because the hbase user has no write permission on hfiles."); } catch (IOException e) { } // Ensure the correct case. USER_CREATE.runAs(bulkLoadAction2); }
private static PermissionStatus fromJSONMap( @SuppressWarnings("rawtypes") Map object) { return new PermissionStatus((String) object.get(OWNER_TAG), (String) object.get(GROUP_TAG), // The initial - below is the Unix file type, // which FsPermission needs there but ignores. FsPermission.valueOf("-" + (String) object.get(PERMISSIONS_TAG))); } }
private static PermissionStatus fromJSONMap( @SuppressWarnings("rawtypes") Map object) { return new PermissionStatus((String) object.get(OWNER_TAG), (String) object.get(GROUP_TAG), // The initial - below is the Unix file type, // which FsPermission needs there but ignores. FsPermission.valueOf("-" + (String) object.get(PERMISSIONS_TAG))); } }
@Override public void flush() throws IOException { super.flush(); if (!Shell.WINDOWS) { Files.setPosixFilePermissions(Paths.get(file.getCanonicalPath()), permissions); } else { // FsPermission expects a 10-character string because of the leading // directory indicator, i.e. "drwx------". The JDK toString method returns // a 9-character string, so prepend a leading character. FsPermission fsPermission = FsPermission.valueOf( "-" + PosixFilePermissions.toString(permissions)); FileUtil.setPermission(file, fsPermission); } }
@Override public void flush() throws IOException { super.flush(); if (!Shell.WINDOWS) { Files.setPosixFilePermissions(Paths.get(file.getCanonicalPath()), permissions); } else { // FsPermission expects a 10-character string because of the leading // directory indicator, i.e. "drwx------". The JDK toString method returns // a 9-character string, so prepend a leading character. FsPermission fsPermission = FsPermission.valueOf( "-" + PosixFilePermissions.toString(permissions)); FileUtil.setPermission(file, fsPermission); } }
@Override public void flush() throws IOException { super.flush(); if (!Shell.WINDOWS) { Files.setPosixFilePermissions(Paths.get(file.getCanonicalPath()), permissions); } else { // FsPermission expects a 10-character string because of the leading // directory indicator, i.e. "drwx------". The JDK toString method returns // a 9-character string, so prepend a leading character. FsPermission fsPermission = FsPermission.valueOf( "-" + PosixFilePermissions.toString(permissions)); FileUtil.setPermission(file, fsPermission); } }
/** * Check that FileStatus are equal if their paths are equal. */ @Test public void testEquals() { Path path = new Path("path"); FileStatus fileStatus1 = new FileStatus(1, true, 1, 1, 1, 1, FsPermission.valueOf("-rw-rw-rw-"), "one", "one", null, path); FileStatus fileStatus2 = new FileStatus(2, true, 2, 2, 2, 2, FsPermission.valueOf("---x--x--x"), "two", "two", null, path); assertEquals(fileStatus1, fileStatus2); }
/** * Check that FileStatus are equal if their paths are equal. */ @Test public void testEquals() { Path path = new Path("path"); FileStatus fileStatus1 = new FileStatus(1, true, 1, 1, 1, 1, FsPermission.valueOf("-rw-rw-rw-"), "one", "one", null, path); FileStatus fileStatus2 = new FileStatus(2, true, 2, 2, 2, 2, FsPermission.valueOf("---x--x--x"), "two", "two", null, path); assertEquals(fileStatus1, fileStatus2); }
private Path initFileSystem(FileSystem fs) throws Exception { Path path = new Path(fs.getWorkingDirectory(), java.util.UUID.randomUUID().toString()); Path testDirInFs = fs.makeQualified(path); System.out.println(XLog.format("Setting FS testcase work dir[{0}]", testDirInFs)); if (fs.exists(testDirInFs)) { setAllPermissions(fs, testDirInFs); } fs.delete(testDirInFs, true); if (!fs.mkdirs(path)) { throw new IOException(XLog.format("Could not create FS testcase dir [{0}]", testDirInFs)); } fs.setOwner(testDirInFs, getTestUser(), getTestGroup()); fs.setPermission(testDirInFs, FsPermission.valueOf("-rwxrwx--x")); return testDirInFs; }
@BeforeClass public static void init() throws IOException { Configuration conf = new Configuration(); conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, tmpFolder.newFolder().getAbsolutePath()); dfsCluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); // make root world-writable so that we can create all location factories as unprivileged user dfsCluster.getFileSystem().setPermission(new Path("/"), FsPermission.valueOf("-rwxrwxrwx")); }
/** * Check that FileStatus are not equal if their paths are not equal. */ @Test public void testNotEquals() { Path path1 = new Path("path1"); Path path2 = new Path("path2"); FileStatus fileStatus1 = new FileStatus(1, true, 1, 1, 1, 1, FsPermission.valueOf("-rw-rw-rw-"), "one", "one", null, path1); FileStatus fileStatus2 = new FileStatus(1, true, 1, 1, 1, 1, FsPermission.valueOf("-rw-rw-rw-"), "one", "one", null, path2); assertFalse(fileStatus1.equals(fileStatus2)); assertFalse(fileStatus2.equals(fileStatus1)); }
/** * Check that FileStatus are not equal if their paths are not equal. */ @Test public void testNotEquals() { Path path1 = new Path("path1"); Path path2 = new Path("path2"); FileStatus fileStatus1 = new FileStatus(1, true, 1, 1, 1, 1, FsPermission.valueOf("-rw-rw-rw-"), "one", "one", null, path1); FileStatus fileStatus2 = new FileStatus(1, true, 1, 1, 1, 1, FsPermission.valueOf("-rw-rw-rw-"), "one", "one", null, path2); assertFalse(fileStatus1.equals(fileStatus2)); assertFalse(fileStatus2.equals(fileStatus1)); }
public void testRetryOnAccessControlError() throws Exception { FsActionExecutor ae = new FsActionExecutor(); FileSystem fs = getFileSystem(); Path path = new Path(getFsTestCaseDir(), "dir"); fs.mkdirs(path); fs.setPermission(path, FsPermission.valueOf("-rwx------")); // do FS operation using different user to cause permission error Context context = createContextWithUser("<fs/>", getTestUser2()); try { ae.chmod(context, path, "-r--------", false, false); fail(); } catch (Exception e) { assertTrue(e instanceof ActionExecutorException); assertEquals("FS014", ((ActionExecutorException) e).getErrorCode()); assertEquals(ActionExecutorException.ErrorType.ERROR, ((ActionExecutorException) e).getErrorType()); } }