From: Tuukka Lehtonen Date: Wed, 28 Mar 2018 13:01:10 +0000 (+0300) Subject: Removed redundant Files.exists/isDirectory checks X-Git-Tag: v1.43.0~136^2~516 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F61%2F1661%2F2;p=simantics%2Fplatform.git Removed redundant Files.exists/isDirectory checks refs #7847 Change-Id: Id2f5936a801ece1828c13e29662c15d61b04abaa --- diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/AcornDatabaseManager.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/AcornDatabaseManager.java index db2c16763..89c29b6d9 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/AcornDatabaseManager.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/AcornDatabaseManager.java @@ -20,8 +20,7 @@ public class AcornDatabaseManager { 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); diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java index 85daddd22..a2cb2fa86 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java @@ -293,9 +293,7 @@ public class ClusterManager { } workingDirectory = dbFolder.resolve(Integer.toString(mainState.headDir)); - if (!Files.exists(workingDirectory)) { - Files.createDirectories(workingDirectory); - } + Files.createDirectories(workingDirectory); cssi.updateWriteDirectory(workingDirectory); diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/backup/AcornBackupProvider.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/backup/AcornBackupProvider.java index a5aa4f2ef..f75d5864f 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/backup/AcornBackupProvider.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/backup/AcornBackupProvider.java @@ -1,6 +1,5 @@ package org.simantics.acorn.backup; -import java.io.BufferedReader; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; @@ -23,6 +22,8 @@ import org.simantics.backup.BackupException; import org.simantics.backup.IBackupProvider; import org.simantics.db.server.ProCoreException; import org.simantics.utils.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Jani @@ -31,6 +32,8 @@ import org.simantics.utils.FileUtils; */ 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); @@ -51,7 +54,7 @@ public class AcornBackupProvider implements IBackupProvider { throw new IllegalStateException(this + " backup provider is already locked"); trId = client.askWriteTransaction(-1).getTransactionId(); } catch (ProCoreException e) { - e.printStackTrace(); + LOGGER.error("Failed to lock backup provider", e); } } @@ -113,7 +116,7 @@ public class AcornBackupProvider implements IBackupProvider { Files.move(restorePath, dbRoot); } } catch (IOException e) { - e.printStackTrace(); + LOGGER.error("Failed to restore database revision {} from backup {}", revision, fromPath.toString(), e); } } @@ -156,7 +159,8 @@ public class AcornBackupProvider implements IBackupProvider { 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; } @@ -202,8 +206,7 @@ public class AcornBackupProvider implements IBackupProvider { 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)); } @@ -261,8 +264,8 @@ public class AcornBackupProvider implements IBackupProvider { @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; diff --git a/bundles/org.simantics.backup/src/org/simantics/backup/BackupProviderService.java b/bundles/org.simantics.backup/src/org/simantics/backup/BackupProviderService.java index 0a40c86f0..3f1aa0e99 100644 --- a/bundles/org.simantics.backup/src/org/simantics/backup/BackupProviderService.java +++ b/bundles/org.simantics.backup/src/org/simantics/backup/BackupProviderService.java @@ -38,8 +38,7 @@ public class BackupProviderService { public static void backup(Path targetPath, int revision, Consumer callback) throws BackupException { List providers = getBackupProviders(); try { - if (!Files.exists(targetPath)) - Files.createDirectories(targetPath); + Files.createDirectories(targetPath); Backups.lock(providers); new Thread(() -> { boolean unlockedAlready = false; diff --git a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java index 9c3f75bf2..74d329901 100644 --- a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java +++ b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java @@ -997,9 +997,9 @@ abstract public class IndexedRelationsSearcherBase { } boolean isIndexAvailable() { - return (Files.exists(indexPath) && Files.isDirectory(indexPath)); + return Files.isDirectory(indexPath); } - + abstract Throwable bestEffortClear(IProgressMonitor monitor, Session session); /* diff --git a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java index 291867451..391f7ed91 100644 --- a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java +++ b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java @@ -43,8 +43,7 @@ public class Activator implements BundleActivator { 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; } @@ -53,8 +52,7 @@ public class Activator implements BundleActivator { 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); } return modelsFolder; } diff --git a/bundles/org.simantics.help.core/src/org/simantics/help/core/Activator.java b/bundles/org.simantics.help.core/src/org/simantics/help/core/Activator.java index 2cfa03db6..80c36be8d 100644 --- a/bundles/org.simantics.help.core/src/org/simantics/help/core/Activator.java +++ b/bundles/org.simantics.help.core/src/org/simantics/help/core/Activator.java @@ -43,8 +43,7 @@ public class Activator extends AbstractUIPlugin { 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"); diff --git a/bundles/org.simantics/src/org/simantics/DatabaseBaselines.java b/bundles/org.simantics/src/org/simantics/DatabaseBaselines.java index ca272be6b..fe3393a2c 100644 --- a/bundles/org.simantics/src/org/simantics/DatabaseBaselines.java +++ b/bundles/org.simantics/src/org/simantics/DatabaseBaselines.java @@ -95,7 +95,7 @@ public class DatabaseBaselines { 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) {