From 13eaa61f3be7ac91c4f0df418ffd6be121905357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Pa=C3=9F?= <22845248+mpass99@users.noreply.github.com> Date: Wed, 2 Feb 2022 12:56:53 +0100 Subject: [PATCH] Fix three bugs in java11Exec detected by the e2e tests. - Fix that one corrupt file breaks the whole execution. - Fix that files with absolute path are saved in the workdir. - Fix that AWS stderr is merged into stdout. --- .../src/main/java/poseidon/App.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/deploy/aws/java11Exec/src/main/java/poseidon/App.java b/deploy/aws/java11Exec/src/main/java/poseidon/App.java index e916167..71f4a64 100644 --- a/deploy/aws/java11Exec/src/main/java/poseidon/App.java +++ b/deploy/aws/java11Exec/src/main/java/poseidon/App.java @@ -78,7 +78,7 @@ public class App implements RequestHandler files) throws IOException { File workspace = Files.createTempDirectory("workspace").toFile(); for (Map.Entry entry : files.entrySet()) { - File f = new File(workspace, entry.getKey()); + try { + File f = new File(entry.getKey()); - f.getParentFile().mkdirs(); - if (!f.getParentFile().exists()) { - throw new IOException("Cannot create parent directories."); + if (!f.isAbsolute()) { + f = new File(workspace, entry.getKey()); + } + + f.getParentFile().mkdirs(); + if (!f.getParentFile().exists()) { + throw new IOException("Cannot create parent directories."); + } + + f.createNewFile(); + if (!f.exists()) { + throw new IOException("Cannot create file."); + } + + Files.write(f.toPath(), Base64.getDecoder().decode(entry.getValue())); + } catch (IOException e) { + this.sendMessage(WebSocketMessageType.WebSocketOutputError, e.toString(), null); } - - f.createNewFile(); - if (!f.exists()) { - throw new IOException("Cannot create file."); - } - - Files.write(f.toPath(), Base64.getDecoder().decode(entry.getValue())); } return workspace; }