refs #7847
Change-Id: Id2f5936a801ece1828c13e29662c15d61b04abaa
public static synchronized Database getDatabase(Path folder) throws ProCoreException {
Path canonical;
try {
public static synchronized Database getDatabase(Path folder) throws ProCoreException {
Path canonical;
try {
- if (!Files.exists(folder))
- Files.createDirectories(folder);
+ Files.createDirectories(folder);
canonical = folder.toRealPath();
} catch (IOException e) {
throw new ProCoreException("Could not get canonical path.", e);
canonical = folder.toRealPath();
} catch (IOException e) {
throw new ProCoreException("Could not get canonical path.", e);
}
workingDirectory = dbFolder.resolve(Integer.toString(mainState.headDir));
}
workingDirectory = dbFolder.resolve(Integer.toString(mainState.headDir));
- if (!Files.exists(workingDirectory)) {
- Files.createDirectories(workingDirectory);
- }
+ Files.createDirectories(workingDirectory);
cssi.updateWriteDirectory(workingDirectory);
cssi.updateWriteDirectory(workingDirectory);
package org.simantics.acorn.backup;
package org.simantics.acorn.backup;
-import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import org.simantics.backup.IBackupProvider;
import org.simantics.db.server.ProCoreException;
import org.simantics.utils.FileUtils;
import org.simantics.backup.IBackupProvider;
import org.simantics.db.server.ProCoreException;
import org.simantics.utils.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
*/
public class AcornBackupProvider implements IBackupProvider {
*/
public class AcornBackupProvider implements IBackupProvider {
+ private static final Logger LOGGER = LoggerFactory.getLogger(AcornBackupProvider.class);
+
private static final String IDENTIFIER = "AcornBackupProvider";
private long trId = -1;
private final Semaphore lock = new Semaphore(1);
private static final String IDENTIFIER = "AcornBackupProvider";
private long trId = -1;
private final Semaphore lock = new Semaphore(1);
throw new IllegalStateException(this + " backup provider is already locked");
trId = client.askWriteTransaction(-1).getTransactionId();
} catch (ProCoreException e) {
throw new IllegalStateException(this + " backup provider is already locked");
trId = client.askWriteTransaction(-1).getTransactionId();
} catch (ProCoreException e) {
+ LOGGER.error("Failed to lock backup provider", e);
Files.move(restorePath, dbRoot);
}
} catch (IOException e) {
Files.move(restorePath, dbRoot);
}
} catch (IOException e) {
+ LOGGER.error("Failed to restore database revision {} from backup {}", revision, fromPath.toString(), e);
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().endsWith(".tar.gz"))
return FileVisitResult.CONTINUE;
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().endsWith(".tar.gz"))
return FileVisitResult.CONTINUE;
- System.out.println("Restore " + file + " to " + toPath.resolve(currentSubFolder.relativize(file)));
+ if (LOGGER.isTraceEnabled())
+ LOGGER.trace("Restore " + file + " to " + toPath.resolve(currentSubFolder.relativize(file)));
Files.copy(file, toPath.resolve(currentSubFolder.relativize(file)), StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
}
Files.copy(file, toPath.resolve(currentSubFolder.relativize(file)), StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
}
private void doBackup() throws IOException {
Path target = targetPath.resolve(String.valueOf(revision)).resolve(IDENTIFIER);
private void doBackup() throws IOException {
Path target = targetPath.resolve(String.valueOf(revision)).resolve(IDENTIFIER);
- if (!Files.exists(target))
- Files.createDirectories(target);
+ Files.createDirectories(target);
Files.walkFileTree(baseDir,
new BackupCopyVisitor(baseDir, target));
}
Files.walkFileTree(baseDir,
new BackupCopyVisitor(baseDir, target));
}
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
- System.out.println("Backup " + file + " to "
- + toPath.resolve(fromPath.relativize(file)));
+ if (LOGGER.isTraceEnabled())
+ LOGGER.trace("Backup " + file + " to " + toPath.resolve(fromPath.relativize(file)));
Files.copy(file, toPath.resolve(fromPath.relativize(file)),
StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
Files.copy(file, toPath.resolve(fromPath.relativize(file)),
StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
public static void backup(Path targetPath, int revision, Consumer<BackupException> callback) throws BackupException {
List<IBackupProvider> providers = getBackupProviders();
try {
public static void backup(Path targetPath, int revision, Consumer<BackupException> callback) throws BackupException {
List<IBackupProvider> providers = getBackupProviders();
try {
- if (!Files.exists(targetPath))
- Files.createDirectories(targetPath);
+ Files.createDirectories(targetPath);
Backups.lock(providers);
new Thread(() -> {
boolean unlockedAlready = false;
Backups.lock(providers);
new Thread(() -> {
boolean unlockedAlready = false;
}
boolean isIndexAvailable() {
}
boolean isIndexAvailable() {
- return (Files.exists(indexPath) && Files.isDirectory(indexPath));
+ return Files.isDirectory(indexPath);
abstract Throwable bestEffortClear(IProgressMonitor monitor, Session session);
/*
abstract Throwable bestEffortClear(IProgressMonitor monitor, Session session);
/*
if (dropinsFolder == null) {
IPath state = Platform.getStateLocation(context.getBundle());
dropinsFolder = Paths.get(state.append("dropins").toOSString());
if (dropinsFolder == null) {
IPath state = Platform.getStateLocation(context.getBundle());
dropinsFolder = Paths.get(state.append("dropins").toOSString());
- if (!Files.exists(dropinsFolder))
- Files.createDirectories(dropinsFolder);
+ Files.createDirectories(dropinsFolder);
}
return dropinsFolder;
}
}
return dropinsFolder;
}
if (modelsFolder == null) {
IPath state = Platform.getStateLocation(context.getBundle());
modelsFolder = Paths.get(state.append("models").toOSString());
if (modelsFolder == null) {
IPath state = Platform.getStateLocation(context.getBundle());
modelsFolder = Paths.get(state.append("models").toOSString());
- if (!Files.exists(modelsFolder))
- Files.createDirectories(modelsFolder);
+ Files.createDirectories(modelsFolder);
IPath path = Platform.getStateLocation(bundle);
Path p = Paths.get(path.toOSString());
directory = p.resolve(HTML_FOLDER);
IPath path = Platform.getStateLocation(bundle);
Path p = Paths.get(path.toOSString());
directory = p.resolve(HTML_FOLDER);
- if (!Files.exists(directory))
- Files.createDirectories(directory);
+ Files.createDirectories(directory);
// Ensure that style.css is inside the html directory
Path css = directory.resolve("style.css");
// Ensure that style.css is inside the html directory
Path css = directory.resolve("style.css");
throw new PlatformException("Database location " + db + " already exists. Cannot re-initialize workspace from baseline.");
if (REQUIRE_INDEX_IN_BASELINE) {
Path index = workspaceLocation.resolve(INDEX_DIRECTORY);
throw new PlatformException("Database location " + db + " already exists. Cannot re-initialize workspace from baseline.");
if (REQUIRE_INDEX_IN_BASELINE) {
Path index = workspaceLocation.resolve(INDEX_DIRECTORY);
- if (!Files.exists(index) || !isEmptyDirectory(index))
+ if (Files.exists(index) || !isEmptyDirectory(index))
throw new PlatformException("Index location " + index + " already exists. Cannot re-initialize workspace from baseline.");
}
} catch (IOException e) {
throw new PlatformException("Index location " + index + " already exists. Cannot re-initialize workspace from baseline.");
}
} catch (IOException e) {