This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit b1ebdc9e943d0bffb5bed62a5d0536ddadd1f4c7 Author: Alex Heneveld <[email protected]> AuthorDate: Mon Jul 19 11:18:54 2021 +0100 Tweak to PR review 1195 - delete temp file --- .../org/apache/brooklyn/rest/resources/ServerResource.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ServerResource.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ServerResource.java index 443d928..f21a318 100644 --- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ServerResource.java +++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ServerResource.java @@ -553,9 +553,10 @@ public class ServerResource extends AbstractBrooklynRestResource implements Serv @Override public Response importPersistenceData(byte[] persistenceData) { + File tempZipFile = null; try { // create a temporary archive where persistence data supplied is written to - File tempZipFile = File.createTempFile("persistence-import",null); + tempZipFile = File.createTempFile("persistence-import",null); Files.write(tempZipFile.toPath(), persistenceData, StandardOpenOption.TRUNCATE_EXISTING); // set path where the data is extracted to - saved in the root of persistence location @@ -628,6 +629,15 @@ public class ServerResource extends AbstractBrooklynRestResource implements Serv ApiError.Builder error = ApiError.builder().errorCode(Response.Status.BAD_REQUEST); error.message(e.getMessage()); return error.build().asJsonResponse(); + } finally { + if (tempZipFile!=null) { + try { + tempZipFile.delete(); + } catch (Exception e) { + Exceptions.propagateIfFatal(e); + log.warn("Failed to delete temp file "+tempZipFile+" (ignoring): "+e, e); + } + } } return Response.ok().build(); }
