/** * Reads the target of the symbolic link * * @param symlink A file that is a symlink * @return A file that is the target of the symlink * @throws java.io.IOException */ public static File readSymbolicLink( File symlink ) throws IOException { Path path = Files.readSymbolicLink( symlink.toPath() ); return path.toFile(); }
public static String readSymlinkTarget(File file) { try { return Files.readSymbolicLink(Paths.get(file.getAbsolutePath())).toString(); } catch (IOException e) { return null; } }
public String perform() { try { Path source = vertx.resolveFile(link).toPath(); return Files.readSymbolicLink(source).toString(); } catch (IOException e) { throw new FileSystemException(e); } } };
/** {@inheritDoc} */ @Override public Path getLinkTarget(Path f) throws IOException { File file = Files.readSymbolicLink(convert(f).toPath()).toFile(); return new Path(file.toURI()); }
/** * @param file File to resolve. * @return Resolved file if it is a symbolic link or original file. * @throws IOException If failed to resolve symlink. */ public static File resolveSymbolicLink(File file) throws IOException { Path path = file.toPath(); return Files.isSymbolicLink(path) ? Files.readSymbolicLink(path).toFile() : file; }
/** * Resolves symlink, if the given file is a symlink. Otherwise return null. * <p> * If the resolution fails, report an error. * * @return * null if the given file is not a symlink. * If the symlink is absolute, the returned string is an absolute path. * If the symlink is relative, the returned string is that relative representation. * The relative path is meant to be resolved from the location of the symlink. */ @CheckForNull public static String resolveSymlink(@Nonnull File link) throws IOException { try { Path path = fileToPath(link); return Files.readSymbolicLink(path).toString(); } catch (UnsupportedOperationException | FileSystemException x) { // no symlinks on this platform (windows?), // or not a link (// Thrown ("Incorrect function.") on JDK 7u21 in Windows 2012 when called on a non-symlink, // rather than NotLinkException, contrary to documentation. Maybe only when not on NTFS?) ? return null; } catch (IOException x) { throw x; } catch (Exception x) { throw new IOException(x); } }
/** * @return File status. */ private FileStatus fileStatus(File file) throws IOException { boolean dir = file.isDirectory(); java.nio.file.Path path = dir ? null : file.toPath(); return new FileStatus(dir ? 0 : file.length(), dir, 1, 4 * 1024, file.lastModified(), file.lastModified(), /*permission*/null, /*owner*/null, /*group*/null, dir ? null : Files.isSymbolicLink(path) ? new Path(Files.readSymbolicLink(path).toUri()) : null, new Path(file.toURI())); }
/** * Checks if link is correct. * * @param link Symbolic link. * @param correctTarget Correct link target. * @return {@code true} If link target is correct. */ private static boolean isJarLinkCorrect(File link, File correctTarget) { if (!Files.isSymbolicLink(link.toPath())) return false; // It is a real file or it does not exist. Path target = null; try { target = Files.readSymbolicLink(link.toPath()); } catch (IOException e) { exit("Failed to read symbolic link: " + link.getAbsolutePath(), e); } return Files.exists(target) && target.toFile().equals(correctTarget); }
Path versionFile = Files.readSymbolicLink(current); Matcher m = VERSION_FILE_PATTERN.matcher(versionFile.getFileName().toString()); if (m.matches()) {
Path linkPath = linkFile.toPath(); Path targetPath = Paths.get(name); if ((!linkFile.exists() || !Files.isSymbolicLink(linkPath) || !Files.readSymbolicLink(linkPath).equals(targetPath)) && !targetPath.isAbsolute() && !targetPath.equals(linkPath.getFileName())) { if (logger.isDebugEnabled()) { Path linkPath2 = linkFile2.toPath(); Path relativeTarget = Paths.get(parent2).relativize(Paths.get(parent)).resolve(name); if ((!linkFile2.exists() || !Files.isSymbolicLink(linkPath2) || !Files.readSymbolicLink(linkPath2).equals(relativeTarget)) && !relativeTarget.isAbsolute() && !relativeTarget.equals(linkPath2.getFileName())) { if (logger.isDebugEnabled()) {
String linkedTo = Files.readSymbolicLink(given).toRealPath().toString(); if (linkedTo.regionMatches(0, wsRoot, 0, wsRoot.length())) { relRoot = linkedTo.substring(wsRoot.length());
try { Path path = file.toPath(), targetPath = Paths.get(target); if ((!file.exists() || !Files.isSymbolicLink(path) || !Files.readSymbolicLink(path).equals(targetPath)) && targetPath.isAbsolute() && !targetPath.equals(path)) { if (logger.isDebugEnabled()) { if ((!file.exists() || !Files.isSymbolicLink(path) || !Files.readSymbolicLink(path).equals(targetPath)) && targetPath.isAbsolute() && !targetPath.equals(path)) { if (logger.isDebugEnabled()) { try { Path path = file.toPath(), urlPath = urlFile.toPath(); if ((!file.exists() || !Files.isSymbolicLink(path) || !Files.readSymbolicLink(path).equals(urlPath)) && urlPath.isAbsolute() && !urlPath.equals(path)) { if (logger.isDebugEnabled()) { if ((!file.exists() || !Files.isSymbolicLink(path) || !Files.readSymbolicLink(path).equals(urlPath)) && urlPath.isAbsolute() && !urlPath.equals(path)) { if (logger.isDebugEnabled()) {
Path linkPath = linkFile.toPath(); Path targetPath = file2.toPath(); if ((!linkFile.exists() || !Files.isSymbolicLink(linkPath) || !Files.readSymbolicLink(linkPath).equals(targetPath)) && targetPath.isAbsolute() && !targetPath.equals(linkPath)) { if (logger.isDebugEnabled()) {
public String perform() { try { Path source = vertx.resolveFile(link).toPath(); return Files.readSymbolicLink(source).toString(); } catch (IOException e) { throw new FileSystemException(e); } } };
/** * Get file length * * @param file * a {@link java.io.File}. * @return length of the given file * @throws java.io.IOException * @since 4.1 */ public static long getLength(File file) throws IOException { Path nioPath = toPath(file); if (Files.isSymbolicLink(nioPath)) return Files.readSymbolicLink(nioPath).toString() .getBytes(UTF_8).length; return Files.size(nioPath); }
path = Files.readSymbolicLink(path); if (!Files.exists(path)) { throw new FileNotFoundException(filePath);
/** * Read target path of the symlink. * * @param path * a {@link java.io.File} object. * @return target path of the symlink, or null if it is not a symbolic link * @throws java.io.IOException * @since 3.0 */ public static String readSymLink(File path) throws IOException { Path nioPath = toPath(path); Path target = Files.readSymbolicLink(nioPath); String targetString = target.toString(); if (SystemReader.getInstance().isWindows()) { targetString = targetString.replace('\\', '/'); } else if (SystemReader.getInstance().isMacOS()) { targetString = Normalizer.normalize(targetString, Form.NFC); } return targetString; }
return path.getParent().resolve(Files.readSymbolicLink(path)); if (Files.exists(path))
private Path resolveLink(Path path) throws IOException { int depth; for (depth = 0; depth < SYMLINK_MAX_DEPTH && Files.isSymbolicLink(path); depth++) { path = Files.readSymbolicLink(path); } if (depth == SYMLINK_MAX_DEPTH) { return null; } else { return path; } }
public static Path mkdirs(Path dir) throws IOException { if (Files.isSymbolicLink(dir)) { return mkdirs(Files.readSymbolicLink(dir)); } return Files.createDirectories(dir); }