public boolean isExecutable(Path path) { return Files.isExecutable(path); }
public boolean isExecutable(Path path) { return Files.isExecutable(path); }
public boolean isSelected(File basedir, String filename, File file) { return file != null && Files.isExecutable(file.toPath()); }
/** * Checks if a storage directory path is accessible. * * @param path the given path * @return true if path exists, false otherwise */ public static boolean isStorageDirAccessible(String path) { Path filePath = Paths.get(path); return Files.exists(filePath) && Files.isReadable(filePath) && Files.isWritable(filePath) && Files.isExecutable(filePath); }
/** * Check whether an executable exists, either at a specific path (if a full path is given) or * on the PATH. * * @param executable the name of an executable on the PATH or a complete path to an executable that may/may not exist * @return whether the executable exists and is executable */ public static boolean executableExists(String executable) { // First check if we've been given the full path already File directFile = new File(executable); if (directFile.exists() && directFile.canExecute()) { return true; } for (String pathString : getSystemPath()) { Path path = Paths.get(pathString); if (Files.exists(path.resolve(executable)) && Files.isExecutable(path.resolve(executable))) { return true; } } return false; }
private int getUnixFileMode(final String pathAsString) { final Path path = Paths.get(pathAsString); if (this.forcedFileMode != null) { return this.getModeValue(path); } try { return (int) Files.getAttribute(path, "unix:mode"); } catch (IOException | UnsupportedOperationException e) { // fallback for non-posix environments int mode = DEFAULT_FILE_MODE; if (Files.isDirectory(path)) { mode = DEFAULT_DIR_MODE; } else if (Files.isExecutable(path)) { mode |= 0111; // equiv to +x for user/group/others } return mode; } }
/** Checks whether the given path denotes an executable file. */ public static void checkFileExistsAndExecutable(Path path) { checkArgument(Files.exists(path), "File '%s' was not found.", path); checkArgument(Files.isExecutable(path), "File '%s' is not executable.", path); }
/** {@inheritDoc} */ @Override public File findHook(Repository repository, String hookName) { final File gitdir = repository.getDirectory(); if (gitdir == null) { return null; } final Path hookPath = gitdir.toPath().resolve(Constants.HOOKS) .resolve(hookName); if (Files.isExecutable(hookPath)) return hookPath.toFile(); return null; }
/** {@inheritDoc} */ @Override public File findHook(Repository repository, String hookName) { final File gitdir = repository.getDirectory(); if (gitdir == null) { return null; } final Path hookPath = gitdir.toPath().resolve(Constants.HOOKS) .resolve(hookName); if (Files.isExecutable(hookPath)) return hookPath.toFile(); return null; } }
/** * Whether the given file can be executed. * * @param file * a {@link java.io.File} object. * @return {@code true} if the given file can be executed. * @since 4.1 */ public static boolean canExecute(File file) { if (!isFile(file)) { return false; } return Files.isExecutable(file.toPath()); }
/** Tries to locate adb utility under "platform-tools". */ public Optional<Path> locateAdb(Path sdkDir) { Path platformToolsDir = sdkDir.resolve("platform-tools"); if (!Files.isDirectory(platformToolsDir)) { return Optional.empty(); } // Expecting to find one entry. try (Stream<Path> pathStream = Files.find( platformToolsDir, /* maxDepth= */ 1, (path, attributes) -> adbPathMatcher.matches(path) && Files.isExecutable(path))) { return pathStream.findFirst(); } catch (IOException e) { throw CommandExecutionException.builder() .withCause(e) .withMessage("Error while trying to locate adb in SDK dir '%s'.", sdkDir) .build(); } } }
@Override public boolean canExecute(String fileName) { return Files.isExecutable(Paths.get(fileName)); }
@Override public boolean canExecute(String fileName) { return Files.isExecutable(Paths.get(fileName)); }
@Override public boolean isExecutable() { return Files.isExecutable(Paths.get(path)); } }
public static boolean isExecutable(String commandName) { for (String dirName : System.getenv("PATH").split(":")) { Path p = Paths.get(dirName).resolve(commandName); if (Files.isRegularFile(p) && Files.isExecutable(p)) { return true; } } return false; } }
/** * @param file * @return {@code true} if the given file can be executed * @since 4.1 */ public static boolean canExecute(File file) { if (!isFile(file)) { return false; } return Files.isExecutable(file.toPath()); }
private String determineDotExecutable() throws IOException { if (this.dotExecutable == null) { return "dot"; } Path dotExecutablePath = this.dotExecutable.toPath(); if (!Files.exists(dotExecutablePath)) { throw new NoSuchFileException("The dot executable '" + this.dotExecutable + "' does not exist."); } else if (Files.isDirectory(dotExecutablePath) || !Files.isExecutable(dotExecutablePath)) { throw new IOException("The dot executable '" + this.dotExecutable + "' is not a file or cannot be executed."); } return dotExecutablePath.toAbsolutePath().toString(); }
@Test // No nonexistant paths are executable public void isExecutableNonexistant() throws IOException { final String path = "path"; Assert.assertFalse(Files.isExecutable(fs.getPath(path))); }
@Override public FileVisitResult visitFile(java.nio.file.Path file, BasicFileAttributes attrs) throws IOException { java.nio.file.Path relativePath = sourceRoot.relativize(file); ContainerSpecification.Artifact.Builder artifact = ContainerSpecification.Artifact.newBuilder() .setSource(new Path(file.toUri())) .setDest(new Path(targetPath, relativePath.toString())) .setExecutable(Files.isExecutable(file)) .setCachable(true) .setExtract(false); env.getArtifacts().add(artifact.build()); return super.visitFile(file, attrs); } });
@Test // All paths are executable public void isExecutable() throws IOException { final String path = "path"; this.getArchive().add(EmptyAsset.INSTANCE, path); Assert.assertTrue(Files.isExecutable(fs.getPath(path))); }