List of usage examples for org.apache.hadoop.fs.permission FsPermission toShort
public short toShort()
From source file:TestFuseDFS.java
License:Apache License
/** * use shell to create a dir and then use filesys to see it exists. *///from w w w.j a va 2 s .c om public void testChmod() throws IOException, InterruptedException, Exception { try { // First create a new directory with mkdirs Path path = new Path("/foo"); Runtime r = Runtime.getRuntime(); String cmd = "mkdir -p " + mpoint + path.toString(); Process p = r.exec(cmd); assertTrue(p.waitFor() == 0); // check it is there assertTrue(fileSys.getFileStatus(path).isDir()); cmd = "chmod 777 " + mpoint + path.toString(); p = r.exec(cmd); assertTrue(p.waitFor() == 0); FileStatus foo = fileSys.getFileStatus(path); FsPermission perm = foo.getPermission(); assertTrue(perm.toShort() == 0777); } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:alluxio.hadoop.AbstractFileSystem.java
License:Apache License
/** * Changes permission of a path./*from ww w . j av a 2 s .c o m*/ * * @param path path to set permission * @param permission permission set to path * @throws IOException if the path failed to be changed permission */ public void setPermission(Path path, FsPermission permission) throws IOException { LOG.info("setMode({},{})", path, permission.toString()); AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); SetAttributeOptions options = SetAttributeOptions.defaults().setMode(permission.toShort()) .setRecursive(false); try { sFileSystem.setAttribute(uri, options); } catch (AlluxioException e) { throw new IOException(e); } }
From source file:com.bigstep.datalake.JsonUtil.java
License:Apache License
private static String toString(final FsPermission permission) { return String.format("%o", permission.toShort()); }
From source file:com.cloudera.hadoop.hdfs.nfs.nfs4.handlers.ACCESSHandler.java
License:Apache License
@Override protected ACCESSResponse doHandle(NFS4Handler server, Session session, ACCESSRequest request) throws NFS4Exception { if (session.getCurrentFileHandle() == null) { throw new NFS4Exception(NFS4ERR_NOFILEHANDLE); }/*from www. j a v a2 s .co m*/ CompoundRequest compoundRequest = session.getCompoundRequest(); AuthenticatedCredentials creds = compoundRequest.getCredentials(); Path path = server.getPath(session.getCurrentFileHandle()); try { UserIDMapper mapper = UserIDMapper.get(session.getConfiguration()); String user = mapper.getUserForUID(creds.getUID(), null); if (user == null) { throw new Exception("Could not map " + creds.getUID() + " to user"); } String group = mapper.getGroupForGID(creds.getGID(), null); if (group == null) { throw new Exception("Could not map " + creds.getGID() + " to group"); } FileSystem fs = session.getFileSystem(); FileStatus fileStatus = fs.getFileStatus(path); FsPermission perms = fileStatus.getPermission(); //FsAction action = perms.getUserAction(); // always comes back ALL?? int permissions = perms.toShort(); int saved = permissions; int rtn = setPerms(permissions, false); permissions = permissions >> 3; if (group.equals(fileStatus.getGroup())) { rtn = setPerms(permissions, true); } permissions = permissions >> 3; if (user.equals(fileStatus.getOwner())) { rtn = setPerms(permissions, true); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Checking access for '" + user + "' and path " + path + " owned by '" + fileStatus.getOwner() + "' permissions " + Integer.toOctalString(saved) + ", Returning " + Integer.toHexString(rtn)); } int access = rtn & request.getAccess(); ACCESSResponse response = createResponse(); response.setStatus(NFS4_OK); response.setAccess(access); response.setSupported(access); return response; } catch (Exception e) { throw new NFS4Exception(NFS4ERR_SERVERFAULT, e); } }
From source file:com.ngdata.sep.impl.SepConsumerIT.java
License:Apache License
static String getDefaultUmask() throws IOException { // Hack to get around the test DFS cluster only wanting to start up if the // umask is set to the expected value (i.e. 022) File tmpDir = Files.createTempDir(); LocalFileSystem local = FileSystem.getLocal(new Configuration()); FileStatus stat = local.getFileStatus(new Path(tmpDir.getAbsolutePath())); FsPermission permission = stat.getPermission(); String permString = Integer.toString(permission.toShort(), 8); tmpDir.delete();/*w w w . jav a 2 s .c o m*/ return permString; }
From source file:com.pigai.hadoop.HttpFSFileSystem.java
License:Apache License
/** * Converts a <code>FsPermission</code> to a Unix octal representation. * /*from w w w . j a va2 s .c o m*/ * @param p * the permission. * * @return the Unix string symbolic reprentation. */ public static String permissionToString(FsPermission p) { return Integer.toString((p == null) ? DEFAULT_PERMISSION : p.toShort(), 8); }
From source file:com.quantcast.qfs.hadoop.Qfs.java
License:Apache License
@Override public FSDataOutputStream createInternal(Path path, EnumSet<CreateFlag> createFlag, FsPermission absolutePermission, int bufferSize, short replication, long blockSize, Progressable progress, ChecksumOpt checksumOpt, boolean createParent) throws IOException { CreateFlag.validate(createFlag);/*ww w . j a v a2 s. co m*/ checkPath(path); if (createParent) { mkdir(path.getParent(), absolutePermission, createParent); } return qfsImpl.create(getUriPath(path), replication, bufferSize, createFlag.contains(CreateFlag.OVERWRITE), absolutePermission.toShort(), createFlag.contains(CreateFlag.APPEND)); }
From source file:com.quantcast.qfs.hadoop.Qfs.java
License:Apache License
@Override public void mkdir(Path dir, FsPermission permission, boolean createParent) throws IOException, UnresolvedLinkException { checkPath(dir);//from w w w .j av a2 s. c o m qfsImpl.retToIoException(createParent ? qfsImpl.mkdirs(getUriPath(dir), permission.toShort()) : qfsImpl.mkdir(getUriPath(dir), permission.toShort())); }
From source file:com.quantcast.qfs.hadoop.QuantcastFileSystem.java
License:Apache License
public boolean mkdirs(Path path, FsPermission permission) throws IOException { return qfsImpl.mkdirs(makeAbsolute(path).toUri().getPath(), permission.toShort()) == 0; }
From source file:com.quantcast.qfs.hadoop.QuantcastFileSystem.java
License:Apache License
public FSDataOutputStream create(Path file, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { Path parent = file.getParent(); if (parent != null && !mkdirs(parent)) { throw new IOException("Mkdirs failed to create " + parent); }//from w w w . j a va 2 s .c o m return qfsImpl.create(makeAbsolute(file).toUri().getPath(), replication, bufferSize, overwrite, permission.toShort()); }