Skip to content

Commit a4b52dd

Browse files
Merge pull request #92 from Codeforces/temp-dir-parent
temp-dir.parent
2 parents c57b34c + 6a831cc commit a4b52dd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

code/src/main/java/com/codeforces/commons/io/internal/UnsafeFileUtil.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,9 +899,15 @@ private static class TempDirHolder {
899899

900900
private static String initializeTempDir() {
901901
try {
902+
String tempDirParent = CommonsPropertiesUtil.getApplicationTempDirParent();
903+
if (tempDirParent != null) {
904+
ensureDirectoryExists(new File(tempDirParent));
905+
}
906+
902907
String tempDirName = CommonsPropertiesUtil.getApplicationTempDirName();
903908

904-
File dir = File.createTempFile(tempDirName, "");
909+
File dir = File.createTempFile(tempDirName, "",
910+
tempDirParent == null ? null : new File(tempDirParent));
905911
File temp = new File(dir.getParentFile(), tempDirName);
906912

907913
if (!dir.delete()) {

code/src/main/java/com/codeforces/commons/properties/internal/CommonsPropertiesUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.codeforces.commons.properties.internal;
22

33
import com.codeforces.commons.properties.PropertiesUtil;
4+
import com.codeforces.commons.text.StringUtil;
45

6+
import java.io.File;
57
import java.util.List;
68

9+
import javax.annotation.Nullable;
10+
711
/**
812
* @author Mike Mirzayanov
913
* @author Maxim Shipko ([email protected])
@@ -30,6 +34,11 @@ public static String getApplicationTempDirName() {
3034
return PropertyValuesHolder.TEMP_DIR_NAME;
3135
}
3236

37+
@Nullable
38+
public static String getApplicationTempDirParent() {
39+
return PropertyValuesHolder.TEMP_DIR_PARENT;
40+
}
41+
3342
public static List<String> getSecurePasswords() {
3443
return PropertyValuesHolder.SECURE_PASSWORDS;
3544
}
@@ -52,6 +61,8 @@ public static String getSubscriptionToken() {
5261

5362
private static final class PropertyValuesHolder {
5463
private static final String TEMP_DIR_NAME = getProperty("temp-dir.name", "temp");
64+
@Nullable
65+
private static final String TEMP_DIR_PARENT = StringUtil.trimToNull(getProperty("temp-dir.parent", null));
5566
private static final List<String> SECURE_PASSWORDS = getListProperty("security.secure-passwords", "");
5667
private static final List<String> SECURE_HOSTS = getListProperty("security.secure-hosts", "");
5768
private static final boolean BYPASS_CERTIFICATE_CHECK

0 commit comments

Comments
 (0)