From 40e4949c475f5e4e784b0d7dee919c9bc0186ca9 Mon Sep 17 00:00:00 2001 From: Gravita Date: Tue, 13 Apr 2021 18:23:39 +0700 Subject: [PATCH] [FEATURE] Use tmpdir for build --- .../src/main/java/pro/gravit/launchserver/LaunchServer.java | 5 +++++ .../java/pro/gravit/launchserver/binary/BinaryPipeline.java | 1 + .../java/pro/gravit/launchserver/binary/LauncherBinary.java | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 73ffb3c8..64eb2c61 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -26,6 +26,7 @@ import pro.gravit.utils.helper.CommonHelper; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.SecurityHelper; import java.io.BufferedReader; import java.io.IOException; @@ -79,6 +80,7 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab * The path to the folder with profiles */ public final Path profilesDir; + public final Path tmpDir; /** * This object contains runtime configuration */ @@ -124,6 +126,7 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, LaunchServerConfig config, LaunchServerRuntimeConfig runtimeConfig, LaunchServerConfigManager launchServerConfigManager, LaunchServerModulesManager modulesManager, KeyAgreementManager keyAgreementManager, CommandHandler commandHandler, CertificateManager certificateManager) throws IOException { this.dir = directories.dir; + this.tmpDir = directories.tmpDir; this.env = env; this.config = config; this.launchServerConfigManager = launchServerConfigManager; @@ -519,6 +522,7 @@ public static class LaunchServerDirectories { public Path keyDirectory; public Path dir; public Path trustStore; + public Path tmpDir; public void collect() { if (updatesDir == null) updatesDir = dir.resolve(UPDATES_NAME); @@ -528,6 +532,7 @@ public void collect() { if (launcherLibrariesCompileDir == null) launcherLibrariesCompileDir = dir.resolve(LAUNCHERLIBRARIESCOMPILE_NAME); if(keyDirectory == null) keyDirectory = dir.resolve(KEY_NAME); + if(tmpDir ==null) tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve(String.format("launchserver-%s", SecurityHelper.randomStringToken())); } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java index 97672dbf..6de409ef 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java @@ -93,6 +93,7 @@ public void build(Path target, boolean deleteTempFiles) throws IOException { long time_end = System.currentTimeMillis(); if (isNeedDelete && deleteTempFiles) IOHelper.move(thisPath, target); else IOHelper.copy(thisPath, target); + IOHelper.deleteDir(buildDir, false); logger.info("Build successful from {} millis", time_end - time_start); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java index 0e211e9e..a4ba76c0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/LauncherBinary.java @@ -13,7 +13,7 @@ public abstract class LauncherBinary extends BinaryPipeline { private volatile byte[] digest; protected LauncherBinary(LaunchServer server, Path binaryFile, String nameFormat) { - super(server.dir.resolve("build"), nameFormat); + super(server.tmpDir.resolve("build"), nameFormat); this.server = server; syncBinaryFile = binaryFile; }