/** * 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); }
/** * 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); } }
/** * 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); } }
/** * 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); } }
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; }
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; }
FileUtil.chmod(executable.toString(), "a+x");
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
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); } } /**
static void createPrivateTempFile(Path p) throws IOException, InterruptedException { createTempFile(p); FileUtil.chmod(p.toString(), "0770",true); }
static void createPublicTempFile(Path p) throws IOException, InterruptedException { createTempFile(p); FileUtil.chmod(p.toString(), "0777",true); }
@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); } }
@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()); }
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; }
/** * 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")); }
@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 } }