diff options
author | Keuin <[email protected]> | 2023-01-13 03:10:48 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-01-13 03:10:48 +0800 |
commit | 97e028f605d1aa060e4a4640a3dd683e51eaef3a (patch) | |
tree | 8b69515fcabfe5fae503dc09987c5c3d9866836a /src/test/java/com/keuin/kbackupfabric/TestUtils.java | |
parent | d7b2dd139f7e17d149a50a2ee777d28dac64b9eb (diff) |
Move temporary files to standard path in IncBackupBackwardCompatibilityTest.
Diffstat (limited to 'src/test/java/com/keuin/kbackupfabric/TestUtils.java')
-rw-r--r-- | src/test/java/com/keuin/kbackupfabric/TestUtils.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/java/com/keuin/kbackupfabric/TestUtils.java b/src/test/java/com/keuin/kbackupfabric/TestUtils.java new file mode 100644 index 0000000..ea98ca1 --- /dev/null +++ b/src/test/java/com/keuin/kbackupfabric/TestUtils.java @@ -0,0 +1,35 @@ +package com.keuin.kbackupfabric; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; + +public class TestUtils { + + public static String getTempDirectory(String subDirectory) throws IOException { + String testTempPath; + String path = System.getenv("KB_TEMP_DIR"); + if (path == null || path.isEmpty() || !new File(path).isDirectory()) { + path = findTempPath(); + } + return Paths.get(path, subDirectory).toString(); + } + + private static String findTempPath() throws IOException { + String path; + if (System.getProperty("os.name").startsWith("Windows")) { + // Windows + path = System.getProperty("java.io.tmpdir"); + } else { + // Unix + path = System.getenv("XDG_RUNTIME_DIR"); + if (!new File(path).isDirectory()) { + path = "/tmp"; + } + } + if (!new File(path).isDirectory()) { + throw new IOException("Cannot find suitable temporary path"); + } + return path; + } +} |