Fixed invalid comparison from AcornBackupProvider.RestoreCopyVisitor 66/1666/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 29 Mar 2018 11:41:33 +0000 (14:41 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 29 Mar 2018 11:41:33 +0000 (14:41 +0300)
Also removed unnecessary Files.exists checks.

refs #7847

Change-Id: I67d9d5a500824a275f4412ef2ecb7c2860f7f1c7

bundles/org.simantics.acorn/src/org/simantics/acorn/backup/AcornBackupProvider.java

index f75d5864fc84040b496565549ec789f7bc09fe2e..cb4b3cdeea1d18f5477387d0fc0e5b4a6a93b2a4 100644 (file)
@@ -139,9 +139,7 @@ public class AcornBackupProvider implements IBackupProvider {
                 return FileVisitResult.CONTINUE;
             } else if (dir.getParent().getFileName().toString().equals(IDENTIFIER)) {
                 Path targetPath = toPath.resolve(dirName);
-                if (!Files.exists(targetPath)) {
-                    Files.createDirectory(targetPath);
-                }
+                Files.createDirectories(targetPath);
                 return FileVisitResult.CONTINUE;
             } else if (dirName.toString().length() == 1 && Character.isDigit(dirName.toString().charAt(0))) {
                 int dirNameInt = Integer.parseInt(dirName.toString());
@@ -240,22 +238,19 @@ public class AcornBackupProvider implements IBackupProvider {
             @Override
             public FileVisitResult preVisitDirectory(Path dir,
                     BasicFileAttributes attrs) throws IOException {
-                Path dirName = dir.getFileName();
-                if (dirName.equals(fromPath)) {
+                if (dir.equals(fromPath)) {
                     Path targetPath = toPath.resolve(fromPath.relativize(dir));
-                    if (!Files.exists(targetPath)) {
-                        Files.createDirectory(targetPath);
-                    }
+                    Files.createDirectories(targetPath);
                     return FileVisitResult.CONTINUE;
                 } else {
-                    int dirNameInt = Integer.parseInt(dirName.toString());
-                    if (latestFolder < dirNameInt && dirNameInt <= newestFolder) {
-                        Path targetPath = toPath.resolve(fromPath
-                                .relativize(dir));
-                        if (!Files.exists(targetPath)) {
-                            Files.createDirectory(targetPath);
+                    try {
+                        int dirNameInt = Integer.parseInt(dir.getFileName().toString());
+                        if (latestFolder < dirNameInt && dirNameInt <= newestFolder) {
+                            Path targetPath = toPath.resolve(fromPath.relativize(dir));
+                            Files.createDirectories(targetPath);
+                            return FileVisitResult.CONTINUE;
                         }
-                        return FileVisitResult.CONTINUE;
+                    } catch (NumberFormatException e) {
                     }
                     return FileVisitResult.SKIP_SUBTREE;
                 }