Search in sources :

Example 1 with DefaultFilePaths

use of com.enonic.xp.repo.impl.dump.DefaultFilePaths in project xp by enonic.

the class AbstractMetaDumpUpgrader method doUpgrade.

@Override
public void doUpgrade(final String dumpName) {
    super.doUpgrade(dumpName);
    final String timeMillis = Long.toString(System.currentTimeMillis());
    FilePaths tmpFilePaths = new DefaultFilePaths() {

        @Override
        public PathRef branchMetaPath(final RepositoryId repositoryId, final Branch branch) {
            return branchRootPath(repositoryId).resolve(branch.toString()).resolve("meta-" + timeMillis + ".tar.gz");
        }

        @Override
        public PathRef versionMetaPath(final RepositoryId repositoryId) {
            return branchRootPath(repositoryId).resolve("versions-" + timeMillis + ".tar.gz");
        }
    };
    tmpDumpReader = FileDumpReader.create(null, basePath, dumpName, tmpFilePaths);
    tmpDumpWriter = FileDumpWriter.create(basePath, dumpName, null, tmpFilePaths);
    try {
        dumpReader.getRepositories().forEach(this::upgradeRepository);
        overwriteSourceFiles();
    } catch (Exception e) {
        try {
            deleteBufferFiles();
        } catch (Exception e2) {
            LOG.error("Error while deleting buffer files", e);
        }
        throw new DumpUpgradeException("Error while upgrading dump [" + dumpName + "]", e);
    } finally {
        try {
            tmpDumpReader.close();
            tmpDumpWriter.close();
        } catch (IOException e) {
            LOG.error("Error while closing dump writer", e);
        }
    }
}
Also used : FilePaths(com.enonic.xp.repo.impl.dump.FilePaths) DefaultFilePaths(com.enonic.xp.repo.impl.dump.DefaultFilePaths) Branch(com.enonic.xp.branch.Branch) DefaultFilePaths(com.enonic.xp.repo.impl.dump.DefaultFilePaths) IOException(java.io.IOException) RepositoryId(com.enonic.xp.repository.RepositoryId) IOException(java.io.IOException)

Example 2 with DefaultFilePaths

use of com.enonic.xp.repo.impl.dump.DefaultFilePaths in project xp by enonic.

the class ZipDumpWriter method create.

public static ZipDumpWriter create(final Path basePath, final String dumpName, final BlobStore blobStore) {
    Preconditions.checkArgument(FileNames.isSafeFileName(dumpName));
    try {
        final ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(Files.newByteChannel(basePath.resolve(dumpName + ZIP_FILE_EXTENSION), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.TRUNCATE_EXISTING));
        final ZipDumpWriteBlobStore zipDumpWriteBlobStore = new ZipDumpWriteBlobStore(dumpName, zipArchiveOutputStream);
        return new ZipDumpWriter(blobStore, new DefaultFilePaths(PathRef.of(dumpName)), zipDumpWriteBlobStore, zipArchiveOutputStream);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : ZipDumpWriteBlobStore(com.enonic.xp.repo.impl.dump.blobstore.ZipDumpWriteBlobStore) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) DefaultFilePaths(com.enonic.xp.repo.impl.dump.DefaultFilePaths) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

DefaultFilePaths (com.enonic.xp.repo.impl.dump.DefaultFilePaths)2 IOException (java.io.IOException)2 Branch (com.enonic.xp.branch.Branch)1 FilePaths (com.enonic.xp.repo.impl.dump.FilePaths)1 ZipDumpWriteBlobStore (com.enonic.xp.repo.impl.dump.blobstore.ZipDumpWriteBlobStore)1 RepositoryId (com.enonic.xp.repository.RepositoryId)1 UncheckedIOException (java.io.UncheckedIOException)1 ZipArchiveOutputStream (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream)1