public boolean isSymbolicLink(Path path) { return Files.isSymbolicLink(path); }
public CleanDirectoryFileVisitor(Path path) { this.path = path; this.symLink = Files.isSymbolicLink(path); }
private CleanDirectoryFileVisitor(Path path) { this.path = path; this.symLink = Files.isSymbolicLink(path); }
CleanTempDirFileVisitor(Path path) { this.path = path; this.symLink = Files.isSymbolicLink(path); }
/** * 判断是否为符号链接文件 * * @param file 被检查的文件 * @return 是否为符号链接文件 * @since 4.4.2 */ public static boolean isSymlink(File file) throws IORuntimeException { return Files.isSymbolicLink(file.toPath()); } }
/** * 判断是否为符号链接文件 * * @param file 被检查的文件 * @return 是否为符号链接文件 * @since 4.4.2 */ public static boolean isSymlink(File file) throws IORuntimeException { return Files.isSymbolicLink(file.toPath()); } }
public static boolean isSymbolicLink( File file ) { return Files.isSymbolicLink( file.toPath() ); }
private Path target(Path path) throws IOException { Path target = path; while (Files.isSymbolicLink(target)) { target = target.toRealPath(); } return target; }
/** * Determines whether the specified file is a symbolic link rather than an actual file. * * @deprecated {@link java.nio.file.Files#isSymbolicLink(java.nio.file.Path)} provides this functionality natively as of Java 1.7. */ @Deprecated public static boolean isSymlink(final File file) { return Files.isSymbolicLink(file.toPath()); }
/** * Determines whether the specified file is a Symbolic Link rather than an actual file. * <p> * Will not return true if there is a Symbolic Link anywhere in the path, * only if the specific file is. * <p> * When using jdk1.7, this method delegates to {@code boolean java.nio.file.Files.isSymbolicLink(Path path)} * * <b>Note:</b> the current implementation always returns {@code false} if running on * jkd1.6 and the system is detected as Windows using {@link FilenameUtils#isSystemWindows()} * <p> * For code that runs on Java 1.7 or later, use the following method instead: * <br> * {@code boolean java.nio.file.Files.isSymbolicLink(Path path)} * @param file the file to check * @return true if the file is a Symbolic Link * @throws IOException if an IO error occurs while checking the file * @since 2.0 */ public static boolean isSymlink(final File file) throws IOException { if (file == null) { throw new NullPointerException("File must not be null"); } return Files.isSymbolicLink(file.toPath()); } }
private boolean isDanglingSymlink(final File f) { if (!Files.isSymbolicLink(f.toPath())) { // it's not a symlink, so clearly it's not a dangling one return false; } // it's a symbolic link, now check the existence of the (target) file (by "following links") final boolean targetFileExists = Files.exists(f.toPath()); return !targetFileExists; } }
private LuceneSearcher(File indexDir) throws IOException { Path path = indexDir.toPath(); // symlinks are not supported here, see https://issues.apache.org/jira/browse/LUCENE-6700, // so we resolve the link ourselves: if (Files.isSymbolicLink(path)) { path = indexDir.getCanonicalFile().toPath(); } this.directory = FSDirectory.open(path); this.reader = DirectoryReader.open(directory); this.searcher = new IndexSearcher(reader); } public IndexReader getReader() {
private static Path createTempFolder(Path workingPath) { try { Path realPath = workingPath; if (Files.isSymbolicLink(realPath)) { realPath = realPath.toRealPath(); } Files.createDirectories(realPath); } catch (IOException e) { throw new IllegalStateException("Failed to create working path: " + workingPath, e); } try { return Files.createTempDirectory(workingPath, TMP_NAME_PREFIX); } catch (IOException e) { throw new IllegalStateException("Failed to create temporary folder in " + workingPath, e); } }
public static void chmod( File file, int mode ) throws IOException { Path path = file.toPath(); if ( !Files.isSymbolicLink( path ) ) { Files.setPosixFilePermissions( path, getPermissions( mode ) ); } }
/** * @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; }
/** * @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())); }
private static void deleteDirectoryImpl(Path path) throws IOException { requireNonNull(path, DIRECTORY_CAN_NOT_BE_NULL); File file = path.toFile(); if (!file.exists()) { return; } checkIO(!Files.isSymbolicLink(path), "Directory '%s' is a symbolic link", path); checkIO(!file.isFile(), "Directory '%s' is a file", path); Files.walkFileTree(path, DeleteRecursivelyFileVisitor.INSTANCE); checkIO(!file.exists(), "Unable to delete directory '%s'", path); }
public void testDeleteRecursively_nonDirectoryFile() throws IOException { try (FileSystem fs = newTestFileSystem(SECURE_DIRECTORY_STREAM)) { Path file = fs.getPath("dir/a"); assertTrue(Files.isRegularFile(file, NOFOLLOW_LINKS)); MoreFiles.deleteRecursively(file); assertFalse(Files.exists(file, NOFOLLOW_LINKS)); Path symlink = fs.getPath("/symlinktodir"); assertTrue(Files.isSymbolicLink(symlink)); Path realSymlinkTarget = symlink.toRealPath(); assertTrue(Files.isDirectory(realSymlinkTarget, NOFOLLOW_LINKS)); MoreFiles.deleteRecursively(symlink); assertFalse(Files.exists(symlink, NOFOLLOW_LINKS)); assertTrue(Files.isDirectory(realSymlinkTarget, NOFOLLOW_LINKS)); } }
@Test public void testLink() throws Exception { String fileName = "some-file.txt"; long fileSize = 1234; createFileWithJunk(fileName, fileSize); String linkName = "some-link.txt"; testLink(linkName, fileName, false, true, v -> { assertEquals(fileSize, fileLength(linkName)); assertFalse(Files.isSymbolicLink(Paths.get(testDir + pathSep + linkName))); }); await(); }
@Test public void testSymLink() throws Exception { // Symlinks require a modified security policy in Windows. -- See http://stackoverflow.com/questions/23217460/how-to-create-soft-symbolic-link-using-java-nio-files Assume.assumeFalse(Utils.isWindows()); String fileName = "some-file.txt"; long fileSize = 1234; createFileWithJunk(fileName, fileSize); String symlinkName = "some-sym-link.txt"; testLink(symlinkName, fileName, true, true, v -> { assertEquals(fileSize, fileLength(symlinkName)); assertTrue(Files.isSymbolicLink(Paths.get(testDir + pathSep + symlinkName))); // Now try reading it String read = vertx.fileSystem().readSymlinkBlocking(testDir + pathSep + symlinkName); assertEquals(fileName, read); }); await(); }