Search in sources :

Example 6 with AtomicMoveNotSupportedException

use of java.nio.file.AtomicMoveNotSupportedException 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 7 with AtomicMoveNotSupportedException

use of java.nio.file.AtomicMoveNotSupportedException in project buck by facebook.

the class Main method moveToTrash.

private static void moveToTrash(ProjectFilesystem filesystem, Console console, BuildId buildId, Path... pathsToMove) throws IOException {
    Path trashPath = filesystem.getBuckPaths().getTrashDir().resolve(buildId.toString());
    filesystem.mkdirs(trashPath);
    for (Path pathToMove : pathsToMove) {
        try {
            // Technically this might throw AtomicMoveNotSupportedException,
            // but we're moving a path within buck-out, so we don't expect this
            // to throw.
            //
            // If it does throw, we'll complain loudly and synchronously delete
            // the file instead.
            filesystem.move(pathToMove, trashPath.resolve(pathToMove.getFileName()), StandardCopyOption.ATOMIC_MOVE);
        } catch (NoSuchFileException e) {
            LOG.verbose(e, "Ignoring missing path %s", pathToMove);
        } catch (AtomicMoveNotSupportedException e) {
            console.getStdErr().format("Atomic moves not supported, falling back to synchronous delete: %s", e);
            MoreFiles.deleteRecursivelyIfExists(pathToMove);
        }
    }
}
Also used : ClassPath(com.google.common.reflect.ClassPath) Path(java.nio.file.Path) NoSuchFileException(java.nio.file.NoSuchFileException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException)

Example 8 with AtomicMoveNotSupportedException

use of java.nio.file.AtomicMoveNotSupportedException in project google-cloud-java by GoogleCloudPlatform.

the class CloudStorageFileSystemProvider method move.

@Override
public void move(Path source, Path target, CopyOption... options) throws IOException {
    initStorage();
    for (CopyOption option : options) {
        if (option == StandardCopyOption.ATOMIC_MOVE) {
            throw new AtomicMoveNotSupportedException(source.toString(), target.toString(), "Google Cloud Storage does not support atomic move operations.");
        }
    }
    copy(source, target, options);
    delete(source);
}
Also used : CopyOption(java.nio.file.CopyOption) StandardCopyOption(java.nio.file.StandardCopyOption) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException)

Aggregations

AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)8 NoSuchFileException (java.nio.file.NoSuchFileException)4 Path (java.nio.file.Path)4 AccessDeniedException (java.nio.file.AccessDeniedException)3 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 FileSystemException (java.nio.file.FileSystemException)3 FileSystemLoopException (java.nio.file.FileSystemLoopException)3 NotDirectoryException (java.nio.file.NotDirectoryException)3 EOFException (java.io.EOFException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)2 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)2 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)2 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)2 LockObtainFailedException (org.apache.lucene.store.LockObtainFailedException)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 ClassPath (com.google.common.reflect.ClassPath)1 CopyOption (java.nio.file.CopyOption)1