Search in sources :

Example 6 with FileSystemLoopException

use of java.nio.file.FileSystemLoopException in project elasticsearch by elastic.

the class StreamOutput method writeException.

public void writeException(Throwable throwable) throws IOException {
    if (throwable == null) {
        writeBoolean(false);
    } else {
        writeBoolean(true);
        boolean writeCause = true;
        boolean writeMessage = true;
        if (throwable instanceof CorruptIndexException) {
            writeVInt(1);
            writeOptionalString(((CorruptIndexException) throwable).getOriginalMessage());
            writeOptionalString(((CorruptIndexException) throwable).getResourceDescription());
            writeMessage = false;
        } else if (throwable instanceof IndexFormatTooNewException) {
            writeVInt(2);
            writeOptionalString(((IndexFormatTooNewException) throwable).getResourceDescription());
            writeInt(((IndexFormatTooNewException) throwable).getVersion());
            writeInt(((IndexFormatTooNewException) throwable).getMinVersion());
            writeInt(((IndexFormatTooNewException) throwable).getMaxVersion());
            writeMessage = false;
            writeCause = false;
        } else if (throwable instanceof IndexFormatTooOldException) {
            writeVInt(3);
            IndexFormatTooOldException t = (IndexFormatTooOldException) throwable;
            writeOptionalString(t.getResourceDescription());
            if (t.getVersion() == null) {
                writeBoolean(false);
                writeOptionalString(t.getReason());
            } else {
                writeBoolean(true);
                writeInt(t.getVersion());
                writeInt(t.getMinVersion());
                writeInt(t.getMaxVersion());
            }
            writeMessage = false;
            writeCause = false;
        } else if (throwable instanceof NullPointerException) {
            writeVInt(4);
            writeCause = false;
        } else if (throwable instanceof NumberFormatException) {
            writeVInt(5);
            writeCause = false;
        } else if (throwable instanceof IllegalArgumentException) {
            writeVInt(6);
        } else if (throwable instanceof AlreadyClosedException) {
            writeVInt(7);
        } else if (throwable instanceof EOFException) {
            writeVInt(8);
            writeCause = false;
        } else if (throwable instanceof SecurityException) {
            writeVInt(9);
        } else if (throwable instanceof StringIndexOutOfBoundsException) {
            writeVInt(10);
            writeCause = false;
        } else if (throwable instanceof ArrayIndexOutOfBoundsException) {
            writeVInt(11);
            writeCause = false;
        } else if (throwable instanceof FileNotFoundException) {
            writeVInt(12);
            writeCause = false;
        } else if (throwable instanceof FileSystemException) {
            writeVInt(13);
            if (throwable instanceof NoSuchFileException) {
                writeVInt(0);
            } else if (throwable instanceof NotDirectoryException) {
                writeVInt(1);
            } else if (throwable instanceof DirectoryNotEmptyException) {
                writeVInt(2);
            } else if (throwable instanceof AtomicMoveNotSupportedException) {
                writeVInt(3);
            } else if (throwable instanceof FileAlreadyExistsException) {
                writeVInt(4);
            } else if (throwable instanceof AccessDeniedException) {
                writeVInt(5);
            } else if (throwable instanceof FileSystemLoopException) {
                writeVInt(6);
            } else {
                writeVInt(7);
            }
            writeOptionalString(((FileSystemException) throwable).getFile());
            writeOptionalString(((FileSystemException) throwable).getOtherFile());
            writeOptionalString(((FileSystemException) throwable).getReason());
            writeCause = false;
        } else if (throwable instanceof IllegalStateException) {
            writeVInt(14);
        } else if (throwable instanceof LockObtainFailedException) {
            writeVInt(15);
        } else if (throwable instanceof InterruptedException) {
            writeVInt(16);
            writeCause = false;
        } else if (throwable instanceof IOException) {
            writeVInt(17);
        } else {
            ElasticsearchException ex;
            if (throwable instanceof ElasticsearchException && ElasticsearchException.isRegistered(throwable.getClass(), version)) {
                ex = (ElasticsearchException) throwable;
            } else {
                ex = new NotSerializableExceptionWrapper(throwable);
            }
            writeVInt(0);
            writeVInt(ElasticsearchException.getId(ex.getClass()));
            ex.writeTo(this);
            return;
        }
        if (writeMessage) {
            writeOptionalString(throwable.getMessage());
        }
        if (writeCause) {
            writeException(throwable.getCause());
        }
        ElasticsearchException.writeStackTraces(throwable, this);
    }
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) AccessDeniedException(java.nio.file.AccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) NoSuchFileException(java.nio.file.NoSuchFileException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) ElasticsearchException(org.elasticsearch.ElasticsearchException) FileSystemException(java.nio.file.FileSystemException) NotDirectoryException(java.nio.file.NotDirectoryException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) EOFException(java.io.EOFException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) IOException(java.io.IOException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) FileSystemLoopException(java.nio.file.FileSystemLoopException)

Example 7 with FileSystemLoopException

use of java.nio.file.FileSystemLoopException in project elasticsearch by elastic.

the class ExceptionSerializationTests method testFileSystemExceptions.

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());
        }
    }
}
Also used : FileSystemException(java.nio.file.FileSystemException) NotDirectoryException(java.nio.file.NotDirectoryException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) AccessDeniedException(java.nio.file.AccessDeniedException) NoSuchFileException(java.nio.file.NoSuchFileException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) FileSystemLoopException(java.nio.file.FileSystemLoopException)

Example 8 with FileSystemLoopException

use of java.nio.file.FileSystemLoopException in project j2objc by google.

the class Files2Test method test_walkFileTree$Path$FileVisitor_FileSystemLoopException.

@Test
public void test_walkFileTree$Path$FileVisitor_FileSystemLoopException() throws IOException {
    // Directory structure.
    // .
    // ├── DATA_FILE
    // └── root
    // └── dir1
    // └── file1
    // 
    // file1 is symlink to dir1
    // Directory Setup.
    Path rootDir = filesSetup.getPathInTestDir("root");
    Path dir1 = filesSetup.getPathInTestDir("root/dir1");
    Path file1 = filesSetup.getPathInTestDir("root/dir1/file1");
    Files.createDirectories(dir1);
    Files.createSymbolicLink(file1, dir1.toAbsolutePath());
    assertEquals(dir1.getFileName(), Files.readSymbolicLink(file1).getFileName());
    Map<Object, VisitOption> dirMap = new HashMap<>();
    Set<FileVisitOption> option = new HashSet<>();
    option.add(FileVisitOption.FOLLOW_LINKS);
    try {
        Files.walkFileTree(rootDir, option, Integer.MAX_VALUE, new Files2Test.TestFileVisitor(dirMap));
        fail();
    } catch (FileSystemLoopException expected) {
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) FileVisitOption(java.nio.file.FileVisitOption) FileSystemLoopException(java.nio.file.FileSystemLoopException) FileVisitOption(java.nio.file.FileVisitOption) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with FileSystemLoopException

use of java.nio.file.FileSystemLoopException in project crate by crate.

the class LocalFsFileInput method expandUri.

@Override
public List<URI> expandUri() throws IOException {
    if (preGlobUri == null) {
        return List.of(uri);
    }
    Path preGlobPath = Paths.get(preGlobUri);
    if (!Files.isDirectory(preGlobPath)) {
        preGlobPath = preGlobPath.getParent();
        if (preGlobPath == null) {
            return List.of();
        }
    }
    if (Files.notExists(preGlobPath)) {
        return List.of();
    }
    final int fileURIDepth = countOccurrences(uri.toString(), '/');
    final int maxDepth = fileURIDepth - countOccurrences(preGlobUri.toString(), '/') + 1;
    final List<URI> uris = new ArrayList<>();
    var fileVisitor = new SimpleFileVisitor<Path>() {

        @Override
        public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
            if (exc instanceof AccessDeniedException) {
                return FileVisitResult.CONTINUE;
            }
            if (exc instanceof FileSystemLoopException) {
                final int maxDepth = fileURIDepth - countOccurrences(file.toUri().toString(), '/') + 1;
                if (maxDepth >= 0) {
                    Files.walkFileTree(file, EnumSet.of(FOLLOW_LINKS), maxDepth, this);
                }
                return FileVisitResult.CONTINUE;
            }
            throw exc;
        }

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
            URI uri = file.toUri();
            if (uriPredicate.test(uri)) {
                uris.add(uri);
            }
            return FileVisitResult.CONTINUE;
        }
    };
    Files.walkFileTree(preGlobPath, EnumSet.of(FOLLOW_LINKS), maxDepth, fileVisitor);
    return uris;
}
Also used : Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) AccessDeniedException(java.nio.file.AccessDeniedException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileSystemLoopException(java.nio.file.FileSystemLoopException) FileReadingIterator.toURI(io.crate.execution.engine.collect.files.FileReadingIterator.toURI) URI(java.net.URI) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Aggregations

FileSystemLoopException (java.nio.file.FileSystemLoopException)9 IOException (java.io.IOException)5 AccessDeniedException (java.nio.file.AccessDeniedException)5 FileSystemException (java.nio.file.FileSystemException)5 FileNotFoundException (java.io.FileNotFoundException)4 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)4 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)4 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)4 NoSuchFileException (java.nio.file.NoSuchFileException)4 NotDirectoryException (java.nio.file.NotDirectoryException)4 EOFException (java.io.EOFException)3 UncheckedIOException (java.io.UncheckedIOException)3 Path (java.nio.file.Path)3 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)3 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)3 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)3 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)3 LockObtainFailedException (org.apache.lucene.store.LockObtainFailedException)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)3 Test (org.junit.Test)3