Search in sources :

Example 26 with DirectoryNotEmptyException

use of java.nio.file.DirectoryNotEmptyException in project structr by structr.

the class StructrFilePath method delete.

@Override
public void delete() throws IOException {
    final App app = StructrApp.getInstance(fs.getSecurityContext());
    final AbstractFile actualFile = getActualFile();
    try (final Tx tx = app.tx()) {
        // if a folder is to be deleted, check contents
        if (actualFile instanceof Folder && ((Folder) actualFile).getChildren().iterator().hasNext()) {
            throw new DirectoryNotEmptyException(getActualFile().getPath());
        } else {
            app.delete(actualFile);
            // remove cached version
            this.cachedActualFile = null;
        }
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("Unable to delete file {}: {}", new Object[] { getActualFile().getPath(), fex.getMessage() });
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) Folder(org.structr.web.entity.Folder)

Example 27 with DirectoryNotEmptyException

use of java.nio.file.DirectoryNotEmptyException in project neo4j by neo4j.

the class BatchingNeoStoresTest method shouldNotOpenStoreWithNodesOrRelationshipsInIt.

@Test
void shouldNotOpenStoreWithNodesOrRelationshipsInIt() throws Throwable {
    Config config = Config.defaults();
    // GIVEN
    someDataInTheDatabase(config);
    // WHEN
    DirectoryNotEmptyException exception = assertThrows(DirectoryNotEmptyException.class, () -> {
        try (JobScheduler jobScheduler = new ThreadPoolJobScheduler()) {
            RecordFormats recordFormats = selectForConfig(Config.defaults(), NullLogProvider.getInstance());
            try (BatchingNeoStores store = batchingNeoStores(fileSystem, databaseLayout, recordFormats, Configuration.DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults(), jobScheduler, PageCacheTracer.NULL, INSTANCE)) {
                store.createNew();
            }
        }
    });
    assertThat(exception.getMessage()).contains("already contains");
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) ForcedSecondaryUnitRecordFormats(org.neo4j.kernel.impl.store.format.ForcedSecondaryUnitRecordFormats) Config(org.neo4j.configuration.Config) RecordFormatSelector.selectForConfig(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForConfig) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Test(org.junit.jupiter.api.Test)

Aggregations

DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)27 NoSuchFileException (java.nio.file.NoSuchFileException)13 Path (java.nio.file.Path)13 IOException (java.io.IOException)11 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)8 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)7 AccessDeniedException (java.nio.file.AccessDeniedException)6 FileSystemException (java.nio.file.FileSystemException)6 NotDirectoryException (java.nio.file.NotDirectoryException)6 FileNotFoundException (java.io.FileNotFoundException)4 FileSystemLoopException (java.nio.file.FileSystemLoopException)4 Test (org.junit.Test)4 EOFException (java.io.EOFException)3 File (java.io.File)3 FileVisitResult (java.nio.file.FileVisitResult)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)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