/** * 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; }
/** * 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(); }
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)); } }
/** * 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))); } }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
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)); } }
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)); } }
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)); } }
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)); } }
/** * 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))); } }
/** * 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))); } }
/** * 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))); } }
/** * 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))); } }
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(); }
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(); }
/** 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(); } }