Skip to content

Commit

Permalink
Revert "Copy models always to temp"
Browse files Browse the repository at this point in the history
This reverts commit 08de82a.
  • Loading branch information
patrickackermann committed Nov 19, 2024
1 parent a32a902 commit b275092
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,21 +308,17 @@ private static TransferDescription getTransferDescription() throws Ili2cExceptio

// prepare path to models from resources
var resourceUri = ObjectMapper.class.getResource(MODELS_RESOURCE).toURI();
tempDir = Files.createTempDirectory("lk2dxf_");
iliModelsPath = tempDir.toString().replace("\\", "/");
if (resourceUri.getScheme().equals("jar")) {
tempDir = Files.createTempDirectory("lk2dxf_");
try (var fs = FileSystems.newFileSystem(resourceUri, Collections.emptyMap());
var sourceFiles = Files.walk(fs.getPath(MODELS_RESOURCE)).filter(Files::isRegularFile)) {
for (var source : sourceFiles.toArray(Path[]::new)) {
Files.copy(source, Paths.get(tempDir.toString(), source.getFileName().toString()));
}
}
iliModelsPath = tempDir.toString().replace("\\", "/");
} else {
try (var sourceFiles = Files.walk(Paths.get(resourceUri))) {
for (var source : sourceFiles.toArray(Path[]::new)) {
Files.copy(source, Paths.get(tempDir.toString(), source.getFileName().toString()));
}
}
iliModelsPath = resourceUri.getPath().replaceFirst("^/", "");
}

try {
Expand All @@ -331,8 +327,10 @@ private static TransferDescription getTransferDescription() throws Ili2cExceptio
var ili2cConfig = modelManager.getConfig(requiredModels, 0.0);
return Ili2c.runCompiler(ili2cConfig);
} finally {
try (var stream = Files.walk(tempDir)) {
stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
if (tempDir != null) {
try (var stream = Files.walk(tempDir)) {
stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
}
}
}
}
Expand Down

0 comments on commit b275092

Please sign in to comment.