From 3a15927b909007100b75b36bd66b854514e25b98 Mon Sep 17 00:00:00 2001 From: Ville Oikarinen Date: Tue, 19 Nov 2024 18:48:23 +0200 Subject: [PATCH] using more /tmp for saving SSD --- .../with/java/org/fluentjava/iwant/entry/Iwant.java | 13 +++++++++++-- .../with/java/org/fluentjava/iwant/entry/Iwant.java | 13 +++++++++++-- .../org/fluentjava/iwant/entry3/CachesImpl.java | 6 ++++++ .../fluentjava/iwant/entry3/WishEvaluatorTest.java | 8 ++++---- .../org/fluentjava/iwant/testarea/TestArea.java | 11 ++++++++--- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/as-iwant-developer/with/java/org/fluentjava/iwant/entry/Iwant.java b/as-iwant-developer/with/java/org/fluentjava/iwant/entry/Iwant.java index 713a8b6f..de80807d 100644 --- a/as-iwant-developer/with/java/org/fluentjava/iwant/entry/Iwant.java +++ b/as-iwant-developer/with/java/org/fluentjava/iwant/entry/Iwant.java @@ -45,6 +45,14 @@ public class Iwant { private static final boolean DEBUG_LOG = "a".contains("b"); + private static final File SYSTEM_TMP_DIR = new File( + System.getProperty("java.io.tmpdir")); + + private static final String USERNAME = System.getProperty("user.name"); + + public static final File IWANT_GLOBAL_TMP_DIR = new File(SYSTEM_TMP_DIR, + ".org.fluentjava.iwant/" + USERNAME); + private static final File HOME = new File(System.getProperty("user.home")); public static final File IWANT_USER_DIR = new File(HOME, @@ -59,6 +67,7 @@ public class Iwant { + EXAMPLE_COMMIT + ".zip\n"; static { + mkdirs(IWANT_GLOBAL_TMP_DIR); mkdirs(IWANT_USER_DIR); } @@ -695,8 +704,8 @@ public static ClassLoader classLoader(ClassLoader parent, } public static void fileLog(String msg) { - try (FileWriter fw = new FileWriter(new File(IWANT_USER_DIR, "log"), - true)) { + try (FileWriter fw = new FileWriter( + new File(IWANT_GLOBAL_TMP_DIR, "log"), true)) { fw.append(new Date().toString()).append(" - ").append(msg) .append("\n"); } catch (IOException e) { diff --git a/essential/iwant-entry/as-some-developer/with/java/org/fluentjava/iwant/entry/Iwant.java b/essential/iwant-entry/as-some-developer/with/java/org/fluentjava/iwant/entry/Iwant.java index 713a8b6f..de80807d 100644 --- a/essential/iwant-entry/as-some-developer/with/java/org/fluentjava/iwant/entry/Iwant.java +++ b/essential/iwant-entry/as-some-developer/with/java/org/fluentjava/iwant/entry/Iwant.java @@ -45,6 +45,14 @@ public class Iwant { private static final boolean DEBUG_LOG = "a".contains("b"); + private static final File SYSTEM_TMP_DIR = new File( + System.getProperty("java.io.tmpdir")); + + private static final String USERNAME = System.getProperty("user.name"); + + public static final File IWANT_GLOBAL_TMP_DIR = new File(SYSTEM_TMP_DIR, + ".org.fluentjava.iwant/" + USERNAME); + private static final File HOME = new File(System.getProperty("user.home")); public static final File IWANT_USER_DIR = new File(HOME, @@ -59,6 +67,7 @@ public class Iwant { + EXAMPLE_COMMIT + ".zip\n"; static { + mkdirs(IWANT_GLOBAL_TMP_DIR); mkdirs(IWANT_USER_DIR); } @@ -695,8 +704,8 @@ public static ClassLoader classLoader(ClassLoader parent, } public static void fileLog(String msg) { - try (FileWriter fw = new FileWriter(new File(IWANT_USER_DIR, "log"), - true)) { + try (FileWriter fw = new FileWriter( + new File(IWANT_GLOBAL_TMP_DIR, "log"), true)) { fw.append(new Date().toString()).append(" - ").append(msg) .append("\n"); } catch (IOException e) { diff --git a/essential/iwant-entry3/src/main/java/org/fluentjava/iwant/entry3/CachesImpl.java b/essential/iwant-entry3/src/main/java/org/fluentjava/iwant/entry3/CachesImpl.java index bfd4284f..6db671fd 100644 --- a/essential/iwant-entry3/src/main/java/org/fluentjava/iwant/entry3/CachesImpl.java +++ b/essential/iwant-entry3/src/main/java/org/fluentjava/iwant/entry3/CachesImpl.java @@ -58,6 +58,12 @@ public File contentDescriptorOf(Target target) { public File temporaryDirectory(String workerName) { File parent = new File(wsCache, "temp"); File tmpDir = new File(parent, workerName); + + // earlier tmpDir was used as such, now we are saving + // SSD and using /tmp instead, simply putting tmpDir as + // child dir for isolation: + tmpDir = new File(Iwant.IWANT_GLOBAL_TMP_DIR + "/" + tmpDir); + Iwant.del(tmpDir); Iwant.mkdirs(tmpDir); return tmpDir; diff --git a/essential/iwant-entry3/src/test/java/org/fluentjava/iwant/entry3/WishEvaluatorTest.java b/essential/iwant-entry3/src/test/java/org/fluentjava/iwant/entry3/WishEvaluatorTest.java index e0e124da..d93f10ee 100644 --- a/essential/iwant-entry3/src/test/java/org/fluentjava/iwant/entry3/WishEvaluatorTest.java +++ b/essential/iwant-entry3/src/test/java/org/fluentjava/iwant/entry3/WishEvaluatorTest.java @@ -594,10 +594,10 @@ public void run() { worker2.start(); worker2.join(); - assertEquals(new File(asSomeone, ".i-cached/temp/worker-1"), - results.get(0)); - assertEquals(new File(asSomeone, ".i-cached/temp/worker-2"), - results.get(1)); + File tempsForThisWs = new File(Iwant.IWANT_GLOBAL_TMP_DIR, + asSomeone + "/.i-cached/temp"); + assertEquals(new File(tempsForThisWs, "worker-1"), results.get(0)); + assertEquals(new File(tempsForThisWs, "worker-2"), results.get(1)); } @Test diff --git a/private/iwant-testarea/src/main/java/org/fluentjava/iwant/testarea/TestArea.java b/private/iwant-testarea/src/main/java/org/fluentjava/iwant/testarea/TestArea.java index a7f7cbec..63d30ea1 100644 --- a/private/iwant-testarea/src/main/java/org/fluentjava/iwant/testarea/TestArea.java +++ b/private/iwant-testarea/src/main/java/org/fluentjava/iwant/testarea/TestArea.java @@ -31,10 +31,15 @@ private File testAreaRoot() { .toURI()); while (wsRootCandidate.getParentFile() != null) { wsRootCandidate = wsRootCandidate.getParentFile(); - File testAreaRootCandidate = new File(wsRootCandidate, + File marker = new File(wsRootCandidate, "private/iwant-testarea/testarea-root"); - if (testAreaRootCandidate.exists()) { - return testAreaRootCandidate; + if (marker.exists()) { + // earlier testarea-root was used as such, now we are saving + // SSD and using /tmp instead, simply putting wsroot as + // child dir for isolation: + File testAreaRoot = new File(Iwant.IWANT_GLOBAL_TMP_DIR, + "iwant-testarea/" + wsRootCandidate); + return testAreaRoot; } } throw new IllegalStateException("Cannot find testarea root");