org.apache.hadoop.fs.FileUtil.chmod()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(169)

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

FileUtil.chmod介绍

[英]Change the permissions on a filename.
[中]更改文件名的权限。

代码示例

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

/**
 * Change the permissions on a filename.
 * @param filename the name of the file to change
 * @param perm the permission string
 * @return the exit code from the command
 * @throws IOException
 * @throws InterruptedException
 */
public static int chmod(String filename, String perm
            ) throws IOException, InterruptedException {
 return chmod(filename, perm, false);
}

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

/**
 * Platform independent implementation for {@link File#setReadable(boolean)}
 * File#setReadable does not work as expected on Windows.
 * @param f input file
 * @param readable
 * @return true on success, false otherwise
 */
public static boolean setReadable(File f, boolean readable) {
 if (Shell.WINDOWS) {
  try {
   String permission = readable ? "u+r" : "u-r";
   FileUtil.chmod(f.getCanonicalPath(), permission, false);
   return true;
  } catch (IOException ex) {
   return false;
  }
 } else {
  return f.setReadable(readable);
 }
}

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

/**
 * Platform independent implementation for {@link File#setWritable(boolean)}
 * File#setWritable does not work as expected on Windows.
 * @param f input file
 * @param writable
 * @return true on success, false otherwise
 */
public static boolean setWritable(File f, boolean writable) {
 if (Shell.WINDOWS) {
  try {
   String permission = writable ? "u+w" : "u-w";
   FileUtil.chmod(f.getCanonicalPath(), permission, false);
   return true;
  } catch (IOException ex) {
   return false;
  }
 } else {
  return f.setWritable(writable);
 }
}

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

/**
 * Platform independent implementation for {@link File#setExecutable(boolean)}
 * File#setExecutable does not work as expected on Windows.
 * Note: revoking execute permission on folders does not have the same
 * behavior on Windows as on Unix platforms. Creating, deleting or renaming
 * a file within that folder will still succeed on Windows.
 * @param f input file
 * @param executable
 * @return true on success, false otherwise
 */
public static boolean setExecutable(File f, boolean executable) {
 if (Shell.WINDOWS) {
  try {
   String permission = executable ? "u+x" : "u-x";
   FileUtil.chmod(f.getCanonicalPath(), permission, false);
   return true;
  } catch (IOException ex) {
   return false;
  }
 } else {
  return f.setExecutable(executable);
 }
}

代码示例来源:origin: apache/hive

private String downloadResource(URI srcUri, String subDir, boolean convertToUnix)
  throws IOException, URISyntaxException {
 LOG.debug("Converting to local {}", srcUri);
 File destinationDir = (subDir == null) ? resourceDir : new File(resourceDir, subDir);
 ensureDirectory(destinationDir);
 File destinationFile = new File(destinationDir, new Path(srcUri.toString()).getName());
 String dest = destinationFile.getCanonicalPath();
 if (destinationFile.exists()) {
  return dest;
 }
 FileSystem fs = FileSystem.get(srcUri, conf);
 fs.copyToLocalFile(new Path(srcUri.toString()), new Path(dest));
 // add "execute" permission to downloaded resource file (needed when loading dll file)
 FileUtil.chmod(dest, "ugo+rx", true);
 return dest;
}

代码示例来源:origin: apache/drill

private String downloadResource(URI srcUri, String subDir, boolean convertToUnix)
  throws IOException, URISyntaxException {
 LOG.info("converting to local " + srcUri);
 File destinationDir = (subDir == null) ? resourceDir : new File(resourceDir, subDir);
 ensureDirectory(destinationDir);
 File destinationFile = new File(destinationDir, new Path(srcUri.toString()).getName());
 String dest = destinationFile.getCanonicalPath();
 if (destinationFile.exists()) {
  return dest;
 }
 FileSystem fs = FileSystem.get(srcUri, conf);
 fs.copyToLocalFile(new Path(srcUri.toString()), new Path(dest));
 // add "execute" permission to downloaded resource file (needed when loading dll file)
 FileUtil.chmod(dest, "ugo+rx", true);
 return dest;
}

代码示例来源:origin: apache/avro

FileUtil.chmod(executable.toString(), "a+x");

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

/**
 * Change the permissions on a filename.
 * @param filename the name of the file to change
 * @param perm the permission string
 * @return the exit code from the command
 * @throws IOException
 * @throws InterruptedException
 */
public static int chmod(String filename, String perm
) throws IOException, InterruptedException {
 return chmod(filename, perm, false);
}

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

/**
 * Change the permissions on a filename.
 * @param filename the name of the file to change
 * @param perm the permission string
 * @return the exit code from the command
 * @throws IOException
 * @throws InterruptedException
 */
public static int chmod(String filename, String perm
            ) throws IOException, InterruptedException {
 return chmod(filename, perm, false);
}

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

/**
 * Change the permissions on a filename.
 * @param filename the name of the file to change
 * @param perm the permission string
 * @return the exit code from the command
 * @throws IOException
 * @throws InterruptedException
 */
public static int chmod(String filename, String perm
            ) throws IOException, InterruptedException {
 return chmod(filename, perm, false);
}

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

/**
 * Change the permissions on a filename.
 * @param filename the name of the file to change
 * @param perm the permission string
 * @return the exit code from the command
 * @throws IOException
 * @throws InterruptedException
 */
public static int chmod(String filename, String perm
            ) throws IOException, InterruptedException {
 return chmod(filename, perm, false);
}

代码示例来源:origin: com.facebook.hadoop/hadoop-core

/**
 * Change the permissions on a filename.
 * @param filename the name of the file to change
 * @param perm the permission string
 * @return the exit code from the command
 * @throws IOException
 * @throws InterruptedException
 */
public static int chmod(String filename, String perm
            ) throws IOException, InterruptedException {
 return chmod(filename, perm, false);
}

代码示例来源:origin: com.facebook.hadoop/hadoop-core

private void changeDirectoryPermissions(String dir, String mode, 
                      boolean isRecursive) {
 int ret = 0;
 try {
  ret = FileUtil.chmod(dir, mode, isRecursive);
 } catch (Exception e) {
  LOG.warn("Exception in changing permissions for directory " + dir + 
        ". Exception: " + e.getMessage());
 }
 if (ret != 0) {
  LOG.warn("Could not change permissions for directory " + dir);
 }
}
/**

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

static void createPrivateTempFile(Path p) 
throws IOException, InterruptedException {
 createTempFile(p);
 FileUtil.chmod(p.toString(), "0770",true);
}

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

static void createPublicTempFile(Path p) 
throws IOException, InterruptedException {
 createTempFile(p);
 FileUtil.chmod(p.toString(), "0777",true);
}

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

@Test
public void testFixesLocalDirPermissions() throws Exception {
 Configuration conf = new Configuration();
 String[] dirs = new String[] {
   TEST_DIR + "/badperms"
 };
 
 new File(dirs[0]).mkdirs();
 FileUtil.chmod(dirs[0], "000");
 conf.setStrings(MRConfig.LOCAL_DIR, dirs);
 setupTaskController(conf);
 
 for (String dir : dirs) {
  checkDir(dir);
 }
}

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

@Test
public void testFixesLogDirPermissions() throws Exception {
 File dir = TaskLog.getUserLogDir();
 FileUtil.fullyDelete(dir);
 dir.mkdirs();
 FileUtil.chmod(dir.getAbsolutePath(), "000");
 
 setupTaskController(new Configuration());
 
 checkDir(dir.getAbsolutePath());
}

代码示例来源:origin: ch.cern.hadoop/hadoop-mapreduce-client-jobclient

private File[] cleanTokenPasswordFile() throws Exception {
 File[] result = new File[2];
 result[0] = new File("./jobTokenPassword");
 if (result[0].exists()) {
  FileUtil.chmod(result[0].getAbsolutePath(), "700");
  assertTrue(result[0].delete());
 }
 result[1] = new File("./.jobTokenPassword.crc");
 if (result[1].exists()) {
  FileUtil.chmod(result[1].getAbsolutePath(), "700");
  result[1].delete();
 }
 return result;
}

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

/** 
 * Prepare directories for a failure, set dir permission to 000
 * @param dir
 * @throws IOException
 * @throws InterruptedException
 */
private void prepareDirToFail(File dir) throws IOException,
  InterruptedException {
 dir.mkdirs();
 assertEquals("Couldn't chmod local vol", 0,
   FileUtil.chmod(dir.toString(), "000"));
}

代码示例来源:origin: ch.cern.hadoop/hadoop-mapreduce-client-jobclient

@Test
public void testToleratesSomeUnwritableVolumes() throws Throwable {
 FileSystem localFileSystem = FileSystem.getLocal(new Configuration());
 String[] vols = new String[]{TEST_ROOT_DIR + "/0",
   TEST_ROOT_DIR + "/1"};
 
 assertTrue(new File(vols[0]).mkdirs());
 assertEquals(0, FileUtil.chmod(vols[0], "400")); // read only
 try {
  new MRAsyncDiskService(localFileSystem, vols);
 } finally {
  FileUtil.chmod(vols[0], "755"); // make writable again
 }
}

相关文章