Skip to content

Commit

Permalink
During version check, create data dir if it doesn't exist (#6605)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
  • Loading branch information
matthew1001 authored Feb 22, 2024
1 parent 094fbb9 commit 4815be8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ public void writeToDirectory(final Path dataDir) throws IOException {
}

private static File getDefaultMetadataFile(final Path dataDir) {
return dataDir.resolve(METADATA_FILENAME).toFile();
File metaDataFile = dataDir.resolve(METADATA_FILENAME).toFile();

// Create the data dir here if it doesn't exist yet
if (!metaDataFile.getParentFile().exists()) {
LOG.info("Data directory {} does not exist - creating it", dataDir);
metaDataFile.getParentFile().mkdirs();
}
return metaDataFile;
}

private static VersionMetadata resolveVersionMetadata(final File metadataFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ void metaFileShouldContain() throws Exception {
assertThat(versionMetadata.getBesuVersion()).isEqualTo("23.10.3");
}

@Test
void dataDirShouldBeCreatedIfNotPresent() throws Exception {
Files.deleteIfExists(temporaryFolder);
assertThat(Files.exists(temporaryFolder)).isFalse();

final VersionMetadata versionMetadata = VersionMetadata.lookUpFrom(temporaryFolder);
assertThat(versionMetadata).isNotNull();

assertThat(Files.exists(temporaryFolder)).isTrue();
}

@Test
void compatibilityCheckShouldThrowExceptionIfEnabled() throws Exception {
// The version file says the last version to start was 23.10.3
Expand Down

0 comments on commit 4815be8

Please sign in to comment.