public void testFileSystemExceptions() throws IOException { for (FileSystemException ex : Arrays.asList(new FileSystemException("a", "b", "c"), new NoSuchFileException("a", "b", "c"), new NotDirectoryException("a"), new DirectoryNotEmptyException("a"), new AtomicMoveNotSupportedException("a", "b", "c"), new FileAlreadyExistsException("a", "b", "c"), new AccessDeniedException("a", "b", "c"), new FileSystemLoopException("a"))) { FileSystemException serialize = serialize(ex); assertEquals(serialize.getClass(), ex.getClass()); assertEquals("a", serialize.getFile()); if (serialize.getClass() == NotDirectoryException.class || serialize.getClass() == FileSystemLoopException.class || serialize.getClass() == DirectoryNotEmptyException.class) { assertNull(serialize.getOtherFile()); assertNull(serialize.getReason()); } else { assertEquals(serialize.getClass().toString(), "b", serialize.getOtherFile()); assertEquals(serialize.getClass().toString(), "c", serialize.getReason()); } } }
private void validateFileSystemLoopException(Path start, Path... causes) { try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) { try { int count = s.mapToInt(p -> 1).reduce(0, Integer::sum); fail("Should got FileSystemLoopException, but got " + count + "elements."); } catch (UncheckedIOException uioe) { IOException ioe = uioe.getCause(); if (ioe instanceof FileSystemLoopException) { FileSystemLoopException fsle = (FileSystemLoopException) ioe; boolean match = false; for (Path cause: causes) { if (fsle.getFile().equals(cause.toString())) { match = true; break; } } assertTrue(match); } else { fail("Unexpected UncheckedIOException cause " + ioe.toString()); } } } catch(IOException ex) { fail("Unexpected IOException " + ex); } }
@Override public FileVisitResult visitFileFailed(Path file, IOException exc) { if (exc instanceof FileSystemLoopException) { LOGGER.error("File system loop/cycle detected: " + file, exc); } else { LOGGER.error("Error while copying resource: " + file, exc); } return CONTINUE; }
@Override public FileVisitResult visitFileFailed(Path file, IOException exc) { if (exc instanceof FileSystemLoopException) { System.err.println("cycle detected: " + file); } else { System.err.format("Unable to copy: %s: %s%n", file, exc); } return CONTINUE; }
@Override public FileVisitResult visitFileFailed(Path file, IOException exc) { if (exc instanceof FileSystemLoopException) { LOGGER.log( Level.WARNING, "Cycle detected: " + file, exc ); } else { LOGGER.log( Level.WARNING, "Unable to copy: " + file, exc ); } return CONTINUE; }
@Override public FileVisitResult visitFileFailed(Path file, IOException exc) { if (exc instanceof FileSystemLoopException) { LOGGER.error("cycle detected: {}", file); } else { LOGGER.error("Unable to copy: {}", file, exc); } return FileVisitResult.CONTINUE; }
@Override public FileVisitResult visitFileFailed(final Path file, final IOException exc) { if (exc instanceof FileSystemLoopException) { System.err.println("cycle detected: " + file); } else { System.err.format("Unable to copy: %s: %s%n", file, exc); } return CONTINUE; }
@Override public FileVisitResult visitFileFailed(Path file, IOException ioe) throws IOException { if (ioe instanceof FileSystemLoopException) { logger.error("cycle detected: " + file); } else { logger.error("Unable to copy: " + file, ioe); } return CONTINUE; }
public static ResolvedPath resolve(EphemeralFsPath path, boolean noFollowLastSymlink) throws FileSystemException { try { if(!path.isAbsolute()) { Path rootPath = path.getFileSystem().getRootPath(); return resolve((EphemeralFsPath) rootPath.resolve(path), noFollowLastSymlink); } //if we look for existing/nonExistent/.. //windows resolves this by skipping looking //up nonExistent, //linux will fail though when it sees the nonExistent Directory if(!path.getFileSystem().getSettings().isPosix()) { path = path.normalize(); } List<EphemeralFsPath> parts = new ArrayList<>(path.splitPaths()); Collections.reverse(parts); List<ResolvedStep> steps = new ArrayList<>(parts.size()); return resolveAbsolutePath(path, path.getFileSystem(), path.getFileSystem().getRoot(), parts, steps, noFollowLastSymlink); } catch(StackOverflowError e) { //recursive links throw new FileSystemLoopException(path + ": Too many levels of symbolic links"); } }
@Override public FileVisitResult visitFileFailed(Path file, IOException exception) throws IOException { if (exception instanceof FileSystemLoopException) { Engine.getLogger().log(Level.SEVERE, "Cycle detected: " + relativise(file), exception); } else { Engine.getLogger().log(Level.SEVERE, "Unable to copy: " + relativise(file), exception); } return CONTINUE; }
@Override public FileVisitResult visitFileFailed(Path file, IOException exc) { if (exc instanceof FileSystemLoopException) { log.error("cycle detected: " + file); } else { log.error(String.format("Unable to copy: %s: %s%n", file, exc)); } return CONTINUE; }
private void ensureNoLoops(Path p, BasicFileAttributes attrs) throws FileSystemLoopException { if (!followLinks) { return; } if (!attrs.isDirectory()) { return; } if (willLoop(p, attrs)) { throw new FileSystemLoopException(p.toString()); } }