Skip to content

Commit

Permalink
using more /tmp for saving SSD
Browse files Browse the repository at this point in the history
  • Loading branch information
wipu committed Nov 19, 2024
1 parent 65972d4 commit 3a15927
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
13 changes: 11 additions & 2 deletions as-iwant-developer/with/java/org/fluentjava/iwant/entry/Iwant.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -59,6 +67,7 @@ public class Iwant {
+ EXAMPLE_COMMIT + ".zip\n";

static {
mkdirs(IWANT_GLOBAL_TMP_DIR);
mkdirs(IWANT_USER_DIR);
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -59,6 +67,7 @@ public class Iwant {
+ EXAMPLE_COMMIT + ".zip\n";

static {
mkdirs(IWANT_GLOBAL_TMP_DIR);
mkdirs(IWANT_USER_DIR);
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 3a15927

Please sign in to comment.