public static boolean isDirectoryReadable(File directory) { return directory.canRead() && directory.canExecute() && directory.listFiles() != null; }
private void validate() { if (!this.binaryExecutable.canExecute()) { throw new RuntimeException("Unable to execute execute-as-user binary. Invalid Path: " + this.binaryExecutable.getAbsolutePath()); } }
public static boolean is_executable(String path) { return new File(path).canExecute(); }
public static boolean pathIsValidSdkHome(String path) { File bin = new File(path, "bin").getAbsoluteFile(); File elixir = new File(bin, "elixir"); File elixirc = new File(bin, "elixirc"); File iex = new File(bin, "iex"); File mix = new File(bin, "mix"); return elixir.canExecute() && elixirc.canExecute() && iex.canExecute() && mix.canExecute(); }
private static String findExecutableOnPath(String name) { for (String dirname : System.getenv("PATH").split(File.pathSeparator)) { File file = new File(dirname, name); if (file.isFile() && file.canExecute()) { return file.getAbsolutePath(); } } return null; }
private static boolean canExecuteExecutable(File file) throws IOException { if (PlatformDependent.javaVersion() < 7) { // Pre-JDK7, the Java API did not directly support POSIX permissions; instead of implementing a custom // work-around, assume true, which disables the check. return true; } // If we can already execute, there is nothing to do. if (file.canExecute()) { return true; } // On volumes, with noexec set, even files with the executable POSIX permissions will fail to execute. // The File#canExecute() method honors this behavior, probaby via parsing the noexec flag when initializing // the UnixFileStore, though the flag is not exposed via a public API. To find out if library is being // loaded off a volume with noexec, confirm or add executalbe permissions, then check File#canExecute(). // Note: We use FQCN to not break when netty is used in java6 Set<java.nio.file.attribute.PosixFilePermission> existingFilePermissions = java.nio.file.Files.getPosixFilePermissions(file.toPath()); Set<java.nio.file.attribute.PosixFilePermission> executePermissions = EnumSet.of(java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE, java.nio.file.attribute.PosixFilePermission.GROUP_EXECUTE, java.nio.file.attribute.PosixFilePermission.OTHERS_EXECUTE); if (existingFilePermissions.containsAll(executePermissions)) { return false; } Set<java.nio.file.attribute.PosixFilePermission> newPermissions = EnumSet.copyOf(existingFilePermissions); newPermissions.addAll(executePermissions); java.nio.file.Files.setPosixFilePermissions(file.toPath(), newPermissions); return file.canExecute(); }
private static List<String> generateCommands(String filePath) { File path = new File(filePath); List<String> commands = new ArrayList<>(); if (path.exists()) { File[] files = path.listFiles(); if (files == null) { return commands; } for (File file : files) { if (!file.isDirectory() && file.canExecute()) { commands.add(file.getAbsolutePath()); } } } LOG.debug("The generated check commands are {}", commands); return commands; }
public String findMvn() { if (mavenLocation == null) { if (System.getenv("M2_HOME") != null) { mavenLocation = System.getenv("M2_HOME") + "/bin/mvn"; return mavenLocation; } for (String dirname : System.getenv("PATH").split(File.pathSeparator)) { File file = new File(dirname, "mvn"); if (file.isFile() && file.canExecute()) { mavenLocation = file.getAbsolutePath(); return mavenLocation; } } throw new RuntimeException("No mvn found, please install mvn by 'conda install maven' or setup M2_HOME"); } return mavenLocation; }
@Override public boolean isValidSdkHome(String path) { File erl = Erlang.getByteCodeInterpreterExecutable(path); return erl.canExecute(); }
@Signature public Memory canExecute(Environment env, Memory... args){ return file.canExecute() ? Memory.TRUE : Memory.FALSE; }
private static boolean canExecuteExecutable(File file) throws IOException { if (PlatformDependent.javaVersion() < 7) { // Pre-JDK7, the Java API did not directly support POSIX permissions; instead of implementing a custom // work-around, assume true, which disables the check. return true; } // If we can already execute, there is nothing to do. if (file.canExecute()) { return true; } // On volumes, with noexec set, even files with the executable POSIX permissions will fail to execute. // The File#canExecute() method honors this behavior, probaby via parsing the noexec flag when initializing // the UnixFileStore, though the flag is not exposed via a public API. To find out if library is being // loaded off a volume with noexec, confirm or add executalbe permissions, then check File#canExecute(). // Note: We use FQCN to not break when netty is used in java6 Set<java.nio.file.attribute.PosixFilePermission> existingFilePermissions = java.nio.file.Files.getPosixFilePermissions(file.toPath()); Set<java.nio.file.attribute.PosixFilePermission> executePermissions = EnumSet.of(java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE, java.nio.file.attribute.PosixFilePermission.GROUP_EXECUTE, java.nio.file.attribute.PosixFilePermission.OTHERS_EXECUTE); if (existingFilePermissions.containsAll(executePermissions)) { return false; } Set<java.nio.file.attribute.PosixFilePermission> newPermissions = EnumSet.copyOf(existingFilePermissions); newPermissions.addAll(executePermissions); java.nio.file.Files.setPosixFilePermissions(file.toPath(), newPermissions); return file.canExecute(); }
@Override public boolean isValidSdkHome(@NotNull String path) { File elixir = Elixir.getScriptInterpreterExecutable(path); File elixirc = Elixir.getByteCodeCompilerExecutable(path); File iex = Elixir.getIExExecutable(path); File mix = Elixir.mixFile(path); // Determine whether everything is can run return elixir.canExecute() && elixirc.canExecute() && iex.canExecute() && mix.canRead(); }
@Override protected GoExecutor patchExecutor(@NotNull GoExecutor executor) throws ExecutionException { if (isDebug()) { File dlv = dlv(); if (dlv.exists() && !dlv.canExecute()) { //noinspection ResultOfMethodCallIgnored dlv.setExecutable(true, false); } return executor.withExePath(dlv.getAbsolutePath()) .withParameters("--listen=localhost:" + myDebugPort, "--headless=true", "exec", myOutputFilePath, "--"); } return executor.showGoEnvVariables(false).withExePath(myOutputFilePath); }
private void init(SystemProperties config) throws IOException { if (config != null && config.customSolcPath() != null) { solc = new File(config.customSolcPath()); if (!solc.canExecute()) { throw new RuntimeException(String.format( "Solidity compiler from config solc.path: %s is not a valid executable", config.customSolcPath() )); } } else { initBundled(); } }
public static void writeFileInfoToConfig(String name, DistributedCacheEntry e, Configuration conf) { int num = conf.getInteger(CACHE_FILE_NUM, 0) + 1; conf.setInteger(CACHE_FILE_NUM, num); conf.setString(CACHE_FILE_NAME + num, name); conf.setString(CACHE_FILE_PATH + num, e.filePath); conf.setBoolean(CACHE_FILE_EXE + num, e.isExecutable || new File(e.filePath).canExecute()); conf.setBoolean(CACHE_FILE_DIR + num, e.isZipped || new File(e.filePath).isDirectory()); if (e.blobKey != null) { conf.setBytes(CACHE_FILE_BLOB_KEY + num, e.blobKey); } }
public CommandSnippets getAllCommandSnippets(String repositoryDirectory) { serverHealthService.update(ServerHealthState.success(HealthStateType.commandRepositoryAccessibilityIssue())); try { File commandRepositoryDirectory = new File(repositoryDirectory); //adding the exists check till packaging command repository with Go story is played. if (commandRepositoryDirectory.isDirectory() && commandRepositoryDirectory.canRead() && commandRepositoryDirectory.canExecute()) { return new CommandSnippets(walk(commandRepositoryDirectory)); } else { throw new IOException("Failed to access command repository located in Go Server Directory at " + repositoryDirectory + ". The directory does not exist or Go does not have sufficient permissions to access it."); } } catch (IOException e) { ServerHealthState serverHealthState = ServerHealthState.warning("Command Repository", e.getMessage(), HealthStateType.commandRepositoryAccessibilityIssue(), systemEnvironment.getCommandRepoWarningTimeout()); serverHealthService.update(serverHealthState); LOGGER.warn(e.getMessage()); } return new CommandSnippets(new ArrayList<>()); }
@Test public void shouldReturnTrueIfDirectoryIsReadable() throws IOException { File readableDirectory = mock(File.class); when(readableDirectory.canRead()).thenReturn(true); when(readableDirectory.canExecute()).thenReturn(true); when(readableDirectory.listFiles()).thenReturn(new File[]{}); assertThat(FileUtil.isDirectoryReadable(readableDirectory), is(true)); File unreadableDirectory = mock(File.class); when(readableDirectory.canRead()).thenReturn(false); when(readableDirectory.canExecute()).thenReturn(false); assertThat(FileUtil.isDirectoryReadable(unreadableDirectory), is(false)); verify(readableDirectory).canRead(); verify(readableDirectory).canExecute(); verify(readableDirectory).listFiles(); verify(unreadableDirectory).canRead(); verify(unreadableDirectory, never()).canExecute(); }
@Override public boolean isValidSdkHome(@NotNull String path) { GoSdkService.LOG.debug("Validating sdk path: " + path); String executablePath = GoSdkService.getGoExecutablePath(path); if (executablePath == null) { GoSdkService.LOG.debug("Go executable is not found: "); return false; } if (!new File(executablePath).canExecute()) { GoSdkService.LOG.debug("Go binary cannot be executed: " + path); return false; } if (getVersionString(path) != null) { GoSdkService.LOG.debug("Cannot retrieve version for sdk: " + path); return true; } return false; }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isSymbolicLink()) { // symbolic link to folder return FileVisitResult.CONTINUE; } TarArchiveEntry tarEntry = new TarArchiveEntry(FilePathUtil.relativize(basePath, file)); if (file.toFile().canExecute()) { tarEntry.setMode(tarEntry.getMode() | 0755); } CompressArchiveUtil.putTarEntry(tarArchiveOutputStream, tarEntry, file); return FileVisitResult.CONTINUE; }
@Override public FileStatus getFileStatus(Path path) throws IOException { File file = pathToFile(path); if (!file.exists()) { throw new FileNotFoundException("Can't find " + path); } // get close enough short mod = 0; if (file.canRead()) { mod |= 0444; } if (file.canWrite()) { mod |= 0200; } if (file.canExecute()) { mod |= 0111; } ShimLoader.getHadoopShims(); return new FileStatus(file.length(), file.isDirectory(), 1, 1024, file.lastModified(), file.lastModified(), FsPermission.createImmutable(mod), "owen", "users", path); } }