protected final int translateOrThrow(Exception exception) { return ExceptionTranslator.<Integer, Exception> of(exception) // .translate(AccessDeniedException.class, e -> -ErrorCodes.EPERM()) // .translate(NoSuchFileException.class, e -> -ErrorCodes.ENOENT()) // .translate(NotDirectoryException.class, e -> -ErrorCodes.ENOTDIR()) // .translate(NotLinkException.class, e -> -ErrorCodes.EINVAL()) // .translate(UnsupportedOperationException.class, e -> -ErrorCodes.ENOSYS()) // .translate(IOException.class, e -> { logger.warn("", e); // Unmapped IOException, log warning return -ErrorCodes.EIO(); }).get(); }
protected void testAllErrors(Try.CheckedConsumer<ExpectedResult, Exception> sut) throws Exception { List<ExpectedResult> list = list( // exp(new NoSuchFileException(null), -ErrorCodes.ENOENT()), // exp(new AccessDeniedException(null), -ErrorCodes.EPERM()), // exp(new NotDirectoryException(null), -ErrorCodes.ENOTDIR()), // exp(new NotLinkException(null), -ErrorCodes.EINVAL()), // exp(new UnsupportedOperationException(), -ErrorCodes.ENOSYS()), // exp(new IOException(), -ErrorCodes.EIO())); // list.forEach(expected -> Try.runWithCatch(() -> sut.accept(expected), Exception.class).get()); }
@Override public File readSymbolicLink(File link) throws IOException { if (!isSymbolicLink(link)) { throw new NotLinkException(link.getPath()); } VirtualFile vf = fileSystem.findFile(link.getPath()); return VfsUtil.virtualToIoFile(symlinks.get(vf)); }
public EphemeralFsPath getRawSymbolicLink(Path parent, EphemeralFsPath fileName) throws FileSystemException { DirectoryEntry entry = children.get(fileName.toFileName()); if(entry == null) { throw new NoSuchFileException(parent.resolve(fileName).toString()); } if(!entry.isSymbolicLink()) { throw new NotLinkException(parent.resolve(fileName).toString()); } return entry.getSymbolicLink(); }
@Test public void testReadSymbolicLinkNoSymbolicLink() throws Exception { Path notSymLink = root.resolve("notSymLink"); Files.createDirectories(notSymLink); try { Files.readSymbolicLink(notSymLink); fail(); } catch(NotLinkException e) { //pass } }
@Override public Path readSymLink(Path path) throws IOException { Path target = symLinks.get(path); if (target == null) { throw new NotLinkException(path.toString()); } return target; }
/** * Checks that this entry exists and links to a symbolic link, throwing an exception if not. * * @return this * @throws NoSuchFileException if this entry does not exist * @throws NotLinkException if this entry does not link to a symbolic link */ public DirectoryEntry requireSymbolicLink(Path pathForException) throws NoSuchFileException, NotLinkException { requireExists(pathForException); if (!file().isSymbolicLink()) { throw new NotLinkException(pathForException.toString()); } return this; }
@Test( expected = NotLinkException.class ) @Category( { SymLink.class } ) public void testGetSymLinkOfNonLinkThrows() throws IOException { Files.readSymbolicLink( targetFile() ); }