]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Removed redundant Files.exists/isDirectory checks 61/1661/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 28 Mar 2018 13:01:10 +0000 (16:01 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 28 Mar 2018 20:07:03 +0000 (23:07 +0300)
refs #7847

Change-Id: Id2f5936a801ece1828c13e29662c15d61b04abaa

bundles/org.simantics.acorn/src/org/simantics/acorn/AcornDatabaseManager.java
bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java
bundles/org.simantics.acorn/src/org/simantics/acorn/backup/AcornBackupProvider.java
bundles/org.simantics.backup/src/org/simantics/backup/BackupProviderService.java
bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java
bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java
bundles/org.simantics.help.core/src/org/simantics/help/core/Activator.java
bundles/org.simantics/src/org/simantics/DatabaseBaselines.java

index db2c16763197a003de5b85bd16de810cd1b8b7da..89c29b6d94b0c1ba38d6a0ffe61e6a67dae6445e 100644 (file)
@@ -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);
index 85daddd22af6d178154c3fcbaa7d3b756b61d894..a2cb2fa864c0cb6b0155a87442cd147e8e527eb6 100644 (file)
@@ -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);
     
index a5aa4f2ef6bcfc7b8d19c70d2a0d7effeca9c4ab..f75d5864fc84040b496565549ec789f7bc09fe2e 100644 (file)
@@ -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;
index 0a40c86f08e3e0da0754653e22840a44040b24fe..3f1aa0e9929aeca128d54f83962972f8432ae843 100644 (file)
@@ -38,8 +38,7 @@ public class BackupProviderService {
     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;
index 9c3f75bf2452b8dfecb61cdc260ea5efe4875516..74d3299018553d1d37f3539ee5fd91cdd6f77dd6 100644 (file)
@@ -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);
 
     /*
index 2918674518aade7bed60e1780686ab5c8d18efea..391f7ed912a07579ffba1603441e56946d73589a 100644 (file)
@@ -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;
     }
index 2cfa03db6fe61795eeadd2ea8e83a6f917ed02bf..80c36be8d688f6e38a6a95aa4fdf964133030dac 100644 (file)
@@ -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");
index ca272be6b3029b6593242df0ddf46b3e00b89ebb..fe3393a2c0afd6f7abb7eb522eb22086b9ed4d51 100644 (file)
@@ -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) {