org.apache.hadoop.util.Shell.getSetPermissionCommand()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中org.apache.hadoop.util.Shell.getSetPermissionCommand()方法的一些代码示例,展示了Shell.getSetPermissionCommand()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Shell.getSetPermissionCommand()方法的具体详情如下:
包路径:org.apache.hadoop.util.Shell
类名称:Shell
方法名:getSetPermissionCommand

Shell.getSetPermissionCommand介绍

[英]Return a command to set permission
[中]返回设置权限的命令

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Return a command to set permission for specific file.
 *
 * @param perm String permission to set
 * @param recursive boolean true to apply to all sub-directories recursively
 * @param file String file to set
 * @return String[] containing command and arguments
 */
public static String[] getSetPermissionCommand(String perm,
                        boolean recursive,
                        String file) {
 String[] baseCmd = getSetPermissionCommand(perm, recursive);
 String[] cmdWithFile = Arrays.copyOf(baseCmd, baseCmd.length + 1);
 cmdWithFile[cmdWithFile.length - 1] = file;
 return cmdWithFile;
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Change the permissions on a file / directory, recursively, if
 * needed.
 * @param filename name of the file whose permissions are to change
 * @param perm permission string
 * @param recursive true, if permissions should be changed recursively
 * @return the exit code from the command.
 * @throws IOException
 */
public static int chmod(String filename, String perm, boolean recursive)
             throws IOException {
 String [] cmd = Shell.getSetPermissionCommand(perm, recursive);
 String[] args = new String[cmd.length + 1];
 System.arraycopy(cmd, 0, args, 0, cmd.length);
 args[cmd.length] = new File(filename).getPath();
 ShellCommandExecutor shExec = new ShellCommandExecutor(args);
 try {
  shExec.execute();
 }catch(IOException e) {
  if(LOG.isDebugEnabled()) {
   LOG.debug("Error while changing permission : " + filename
        +" Exception: " + StringUtils.stringifyException(e));
  }
 }
 return shExec.getExitCode();
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

private static void execSetPermission(File f,
                   FsPermission permission
                   )  throws IOException {
 if (NativeIO.isAvailable()) {
  NativeIO.POSIX.chmod(f.getCanonicalPath(), permission.toShort());
 } else {
  execCommand(f, Shell.getSetPermissionCommand(
        String.format("%04o", permission.toShort()), false));
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Use the command chmod to set permission.
 */
@Override
public void setPermission(Path p, FsPermission permission)
 throws IOException {
 if (NativeIO.isAvailable()) {
  NativeIO.POSIX.chmod(pathToFile(p).getCanonicalPath(),
          permission.toShort());
 } else {
  String perm = String.format("%04o", permission.toShort());
  Shell.execCommand(Shell.getSetPermissionCommand(perm, false,
   FileUtil.makeShellPath(pathToFile(p), true)));
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

/**
 * Return a command to set permission for specific file.
 * 
 * @param perm String permission to set
 * @param recursive boolean true to apply to all sub-directories recursively
 * @param file String file to set
 * @return String[] containing command and arguments
 */
public static String[] getSetPermissionCommand(String perm, boolean recursive,
                        String file) {
 String[] baseCmd = getSetPermissionCommand(perm, recursive);
 String[] cmdWithFile = Arrays.copyOf(baseCmd, baseCmd.length + 1);
 cmdWithFile[cmdWithFile.length - 1] = file;
 return cmdWithFile;
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

/**
 * Return a command to set permission for specific file.
 * 
 * @param perm String permission to set
 * @param recursive boolean true to apply to all sub-directories recursively
 * @param file String file to set
 * @return String[] containing command and arguments
 */
public static String[] getSetPermissionCommand(String perm, boolean recursive,
                        String file) {
 String[] baseCmd = getSetPermissionCommand(perm, recursive);
 String[] cmdWithFile = Arrays.copyOf(baseCmd, baseCmd.length + 1);
 cmdWithFile[cmdWithFile.length - 1] = file;
 return cmdWithFile;
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * Return a command to set permission for specific file.
 * 
 * @param perm String permission to set
 * @param recursive boolean true to apply to all sub-directories recursively
 * @param file String file to set
 * @return String[] containing command and arguments
 */
public static String[] getSetPermissionCommand(String perm, boolean recursive,
                        String file) {
 String[] baseCmd = getSetPermissionCommand(perm, recursive);
 String[] cmdWithFile = Arrays.copyOf(baseCmd, baseCmd.length + 1);
 cmdWithFile[cmdWithFile.length - 1] = file;
 return cmdWithFile;
}

代码示例来源:origin: io.hops/hadoop-common

/**
 * Return a command to set permission for specific file.
 *
 * @param perm String permission to set
 * @param recursive boolean true to apply to all sub-directories recursively
 * @param file String file to set
 * @return String[] containing command and arguments
 */
public static String[] getSetPermissionCommand(String perm,
                        boolean recursive,
                        String file) {
 String[] baseCmd = getSetPermissionCommand(perm, recursive);
 String[] cmdWithFile = Arrays.copyOf(baseCmd, baseCmd.length + 1);
 cmdWithFile[cmdWithFile.length - 1] = file;
 return cmdWithFile;
}

代码示例来源:origin: cdapio/cdap

/**
 * Return a command to set permission for specific file.
 * 
 * @param perm String permission to set
 * @param recursive boolean true to apply to all sub-directories recursively
 * @param file String file to set
 * @return String[] containing command and arguments
 */
public static String[] getSetPermissionCommand(String perm, boolean recursive,
                        String file) {
 String[] baseCmd = getSetPermissionCommand(perm, recursive);
 String[] cmdWithFile = Arrays.copyOf(baseCmd, baseCmd.length + 1);
 cmdWithFile[cmdWithFile.length - 1] = file;
 return cmdWithFile;
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

private static void execSetPermission(File f, 
                   FsPermission permission
                   )  throws IOException {
 if (NativeIO.isAvailable()) {
  NativeIO.POSIX.chmod(f.getCanonicalPath(), permission.toShort());
 } else {
  execCommand(f, Shell.getSetPermissionCommand(
        String.format("%04o", permission.toShort()), false));
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

private static void execSetPermission(File f, 
                   FsPermission permission
                   )  throws IOException {
 if (NativeIO.isAvailable()) {
  NativeIO.POSIX.chmod(f.getCanonicalPath(), permission.toShort());
 } else {
  execCommand(f, Shell.getSetPermissionCommand(
        String.format("%04o", permission.toShort()), false));
 }
}

代码示例来源:origin: io.hops/hadoop-common

private static void execSetPermission(File f,
  FsPermission permission
)  throws IOException {
 if (NativeIO.isAvailable()) {
  NativeIO.POSIX.chmod(f.getCanonicalPath(), permission.toShort());
 } else {
  execCommand(f, Shell.getSetPermissionCommand(
    String.format("%04o", permission.toShort()), false));
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

private static void execSetPermission(File f, 
                   FsPermission permission
                   )  throws IOException {
 if (NativeIO.isAvailable()) {
  NativeIO.POSIX.chmod(f.getCanonicalPath(), permission.toShort());
 } else {
  execCommand(f, Shell.getSetPermissionCommand(
        String.format("%04o", permission.toShort()), false));
 }
}

代码示例来源:origin: io.hops/hadoop-common

/**
 * Use the command chmod to set permission.
 */
@Override
public void setPermission(Path p, FsPermission permission)
 throws IOException {
 if (NativeIO.isAvailable()) {
  NativeIO.POSIX.chmod(pathToFile(p).getCanonicalPath(),
          permission.toShort());
 } else {
  String perm = String.format("%04o", permission.toShort());
  Shell.execCommand(Shell.getSetPermissionCommand(perm, false,
   FileUtil.makeShellPath(pathToFile(p), true)));
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * Use the command chmod to set permission.
 */
@Override
public void setPermission(Path p, FsPermission permission)
 throws IOException {
 if (NativeIO.isAvailable()) {
  NativeIO.POSIX.chmod(pathToFile(p).getCanonicalPath(),
          permission.toShort());
 } else {
  String perm = String.format("%04o", permission.toShort());
  Shell.execCommand(Shell.getSetPermissionCommand(perm, false,
   FileUtil.makeShellPath(pathToFile(p), true)));
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

/**
 * Use the command chmod to set permission.
 */
@Override
public void setPermission(Path p, FsPermission permission)
 throws IOException {
 if (NativeIO.isAvailable()) {
  NativeIO.POSIX.chmod(pathToFile(p).getCanonicalPath(),
          permission.toShort());
 } else {
  String perm = String.format("%04o", permission.toShort());
  Shell.execCommand(Shell.getSetPermissionCommand(perm, false,
   FileUtil.makeShellPath(pathToFile(p), true)));
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

/**
 * Use the command chmod to set permission.
 */
@Override
public void setPermission(Path p, FsPermission permission)
 throws IOException {
 if (NativeIO.isAvailable()) {
  NativeIO.POSIX.chmod(pathToFile(p).getCanonicalPath(),
          permission.toShort());
 } else {
  String perm = String.format("%04o", permission.toShort());
  Shell.execCommand(Shell.getSetPermissionCommand(perm, false,
   FileUtil.makeShellPath(pathToFile(p), true)));
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

private void _checkDirs(boolean isDir, FsPermission perm, boolean success)
  throws Throwable {
 File localDir = File.createTempFile("test", "tmp");
 if (isDir) {
  localDir.delete();
  localDir.mkdir();
 }
 Shell.execCommand(Shell.getSetPermissionCommand(String.format("%04o",
  perm.toShort()), false, localDir.getAbsolutePath()));
 try {
  DiskChecker.checkDir(FileSystem.getLocal(new Configuration()),
   new Path(localDir.getAbsolutePath()), perm);
  assertTrue("checkDir success", success);
 } catch (DiskErrorException e) {
  assertFalse("checkDir success", success);
 }
 localDir.delete();
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

private void _checkDirs(boolean isDir, FsPermission perm, boolean success)
  throws Throwable {
 File localDir = File.createTempFile("test", "tmp");
 if (isDir) {
  localDir.delete();
  localDir.mkdir();
 }
 Shell.execCommand(Shell.getSetPermissionCommand(String.format("%04o",
  perm.toShort()), false, localDir.getAbsolutePath()));
 try {
  DiskChecker.checkDir(FileSystem.getLocal(new Configuration()),
   new Path(localDir.getAbsolutePath()), perm);
  assertTrue("checkDir success", success);
 } catch (DiskErrorException e) {
  assertFalse("checkDir success", success);
 }
 localDir.delete();
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

/** Test no side effect files are left over. After creating a temp
 * temp file, remove both the temp file and its parent. Verify that
 * no files or directories are left over as can happen when File objects
 * are mistakenly created from fully qualified path strings.
 * @throws IOException
 */
@Test (timeout = 30000)
public void testNoSideEffects() throws IOException {
 assumeTrue(!isWindows);
 String dir = buildBufferDir(ROOT, 0);
 try {
  conf.set(CONTEXT, dir);
  File result = dirAllocator.createTmpFileForWrite(FILENAME, -1, conf);
  assertTrue(result.delete());
  assertTrue(result.getParentFile().delete());
  assertFalse(new File(dir).exists());
 } finally {
  Shell.execCommand(Shell.getSetPermissionCommand("u+w", false,
                          BUFFER_DIR_ROOT));
  rmBufferDirs();
 }
}

相关文章

微信公众号

最新文章

更多