- private static final DateTimeFormatter TIMESTAMP_FORMAT = DateTimeFormatter.ofPattern("d. MMM yyyy HH:mm:ss");
-
- private static byte[] baselineIndicatorContents(Path path) throws IOException {
- return String.format("%s%n%s%n",
- path.toString(),
- Instant.now().atZone(ZoneId.systemDefault()).format(TIMESTAMP_FORMAT))
- .getBytes("UTF-8");
- }
-
- private void validateWorkspaceForBaselineInitialization(Path workspaceLocation) throws PlatformException {
- try {
- Path db = workspaceLocation.resolve("db");
- if (Files.exists(db))
- throw new PlatformException("Database location " + db + " already exists. Cannot re-initialize workspace from baseline.");
- Path index = workspaceLocation.resolve(".metadata/.plugins/org.simantics.db.indexing");
- 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("Failed to validate workspace for baseline initialization", e);
- }
- }
-
- private static boolean isEmptyDirectory(Path dir) throws IOException {
- return Files.walk(dir).count() == 1;
- }
-
- private void validateBaselineFile(Path baseline) throws PlatformException {
- try (ZipFile zip = new ZipFile(baseline.toFile())) {
- ZipEntry db = zip.getEntry("db");
- if (db == null)
- throw new PlatformException("Baseline archive does not contain database directory 'db'");
- ZipEntry index = zip.getEntry(".metadata/.plugins/org.simantics.db.indexing");
- if (index == null)
- throw new PlatformException("Baseline archive does not contain database index directory '.metadata/.plugins/org.simantics.db.indexing'");
- } catch (IOException e) {
- throw new PlatformException("Failed to validate baseline archive " + baseline, e);
- }
- }
-