forked from Qortal/qortal
Switched all system-generated temp paths to a user specified "tempDataPath".
This ensures that the temporary files are being kept with the rest of the data, rather than somewhere inappropriate such as on flash storage. It also allows the user to locate them somewhere else, such as on a dedicated drive.
This commit is contained in:
parent
8dac3ebf96
commit
63f5946527
@ -3,12 +3,14 @@ package org.qortal.arbitrary;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.crypto.Crypto;
|
||||
import org.qortal.settings.Settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ArbitraryDataDiff {
|
||||
|
||||
@ -17,6 +19,7 @@ public class ArbitraryDataDiff {
|
||||
private Path pathBefore;
|
||||
private Path pathAfter;
|
||||
private Path diffPath;
|
||||
private String identifier;
|
||||
|
||||
public ArbitraryDataDiff(Path pathBefore, Path pathAfter) {
|
||||
this.pathBefore = pathBefore;
|
||||
@ -35,6 +38,7 @@ public class ArbitraryDataDiff {
|
||||
}
|
||||
|
||||
private void preExecute() {
|
||||
this.createRandomIdentifier();
|
||||
this.createOutputDirectory();
|
||||
}
|
||||
|
||||
@ -42,11 +46,16 @@ public class ArbitraryDataDiff {
|
||||
|
||||
}
|
||||
|
||||
private void createRandomIdentifier() {
|
||||
this.identifier = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
private void createOutputDirectory() {
|
||||
// Ensure temp folder exists
|
||||
Path tempDir;
|
||||
// Use the user-specified temp dir, as it is deterministic, and is more likely to be located on reusable storage hardware
|
||||
String baseDir = Settings.getInstance().getTempDataPath();
|
||||
Path tempDir = Paths.get(baseDir, "diff", this.identifier);
|
||||
try {
|
||||
tempDir = Files.createTempDirectory("qortal-diff");
|
||||
Files.createDirectories(tempDir);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Unable to create temp directory");
|
||||
}
|
||||
|
@ -255,13 +255,15 @@ public class ArbitraryDataFile {
|
||||
if (this.chunks != null && this.chunks.size() > 0) {
|
||||
|
||||
// Create temporary path for joined file
|
||||
Path tempPath;
|
||||
// Use the user-specified temp dir, as it is deterministic, and is more likely to be located on reusable storage hardware
|
||||
String baseDir = Settings.getInstance().getTempDataPath();
|
||||
Path tempDir = Paths.get(baseDir, "join", this.chunks.get(0).digest58());
|
||||
try {
|
||||
tempPath = Files.createTempFile(this.chunks.get(0).digest58(), ".tmp");
|
||||
Files.createDirectories(tempDir);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
this.filePath = tempPath.toString();
|
||||
this.filePath = tempDir.toString();
|
||||
|
||||
// Join the chunks
|
||||
File outputFile = new File(this.filePath);
|
||||
@ -279,8 +281,8 @@ public class ArbitraryDataFile {
|
||||
out.close();
|
||||
|
||||
// Copy temporary file to data directory
|
||||
this.filePath = this.copyToDataDirectory(tempPath);
|
||||
Files.delete(tempPath);
|
||||
this.filePath = this.copyToDataDirectory(tempDir);
|
||||
Files.delete(tempDir);
|
||||
|
||||
return true;
|
||||
} catch (FileNotFoundException e) {
|
||||
|
@ -4,6 +4,7 @@ import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.crypto.Crypto;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.utils.FilesystemUtils;
|
||||
|
||||
import java.io.File;
|
||||
@ -11,6 +12,7 @@ import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ArbitraryDataMerge {
|
||||
|
||||
@ -19,6 +21,7 @@ public class ArbitraryDataMerge {
|
||||
private Path pathBefore;
|
||||
private Path pathAfter;
|
||||
private Path mergePath;
|
||||
private String identifier;
|
||||
|
||||
public ArbitraryDataMerge(Path pathBefore, Path pathAfter) {
|
||||
this.pathBefore = pathBefore;
|
||||
@ -37,6 +40,7 @@ public class ArbitraryDataMerge {
|
||||
}
|
||||
|
||||
private void preExecute() {
|
||||
this.createRandomIdentifier();
|
||||
this.createOutputDirectory();
|
||||
}
|
||||
|
||||
@ -44,11 +48,16 @@ public class ArbitraryDataMerge {
|
||||
|
||||
}
|
||||
|
||||
private void createRandomIdentifier() {
|
||||
this.identifier = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
private void createOutputDirectory() {
|
||||
// Ensure temp folder exists
|
||||
Path tempDir;
|
||||
// Use the user-specified temp dir, as it is deterministic, and is more likely to be located on reusable storage hardware
|
||||
String baseDir = Settings.getInstance().getTempDataPath();
|
||||
Path tempDir = Paths.get(baseDir, "merge", this.identifier);
|
||||
try {
|
||||
tempDir = Files.createTempDirectory("qortal-diff");
|
||||
Files.createDirectories(tempDir);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Unable to create temp directory");
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.qortal.repository.DataException;
|
||||
import org.qortal.repository.Repository;
|
||||
import org.qortal.repository.RepositoryManager;
|
||||
import org.qortal.arbitrary.ArbitraryDataFile.*;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.transform.Transformer;
|
||||
import org.qortal.utils.Base58;
|
||||
import org.qortal.utils.FilesystemUtils;
|
||||
@ -81,9 +82,9 @@ public class ArbitraryDataReader {
|
||||
}
|
||||
|
||||
private void createWorkingDirectory() {
|
||||
// Use the system tmpdir as our base, as it is deterministic
|
||||
String baseDir = System.getProperty("java.io.tmpdir");
|
||||
Path tempDir = Paths.get(baseDir + File.separator + "qortal" + File.separator + this.resourceId);
|
||||
// Use the user-specified temp dir, as it is deterministic, and is more likely to be located on reusable storage hardware
|
||||
String baseDir = Settings.getInstance().getTempDataPath();
|
||||
Path tempDir = Paths.get(baseDir, "reader", this.resourceId);
|
||||
try {
|
||||
Files.createDirectories(tempDir);
|
||||
} catch (IOException e) {
|
||||
@ -93,7 +94,6 @@ public class ArbitraryDataReader {
|
||||
}
|
||||
|
||||
private void createUncompressedDirectory() {
|
||||
// Use the system tmpdir as our base, as it is deterministic
|
||||
this.uncompressedPath = Paths.get(this.workingPath.toString() + File.separator + "data");
|
||||
try {
|
||||
Files.createDirectories(this.uncompressedPath);
|
||||
|
@ -3,10 +3,13 @@ package org.qortal.arbitrary;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.crypto.Crypto;
|
||||
import org.qortal.data.transaction.ArbitraryTransactionData.*;
|
||||
import org.qortal.crypto.AES;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.arbitrary.ArbitraryDataFile.*;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.utils.Base58;
|
||||
import org.qortal.utils.ZipUtils;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
@ -78,10 +81,12 @@ public class ArbitraryDataWriter {
|
||||
}
|
||||
|
||||
private void createWorkingDirectory() {
|
||||
// Ensure temp folder exists
|
||||
Path tempDir;
|
||||
// Use the user-specified temp dir, as it is deterministic, and is more likely to be located on reusable storage hardware
|
||||
String baseDir = Settings.getInstance().getTempDataPath();
|
||||
String identifier = Crypto.digest(this.filePath.toString().getBytes()).toString();
|
||||
Path tempDir = Paths.get(baseDir, "writer", identifier);
|
||||
try {
|
||||
tempDir = Files.createTempDirectory("qortal");
|
||||
Files.createDirectories(tempDir);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Unable to create temp directory");
|
||||
}
|
||||
|
@ -206,6 +206,8 @@ public class Settings {
|
||||
|
||||
/** Data storage path. */
|
||||
private String dataPath = "data";
|
||||
/** Data storage path (for temporary data). */
|
||||
private String tempDataPath = "data/_temp";
|
||||
|
||||
|
||||
// Domain mapping
|
||||
@ -627,4 +629,8 @@ public class Settings {
|
||||
public String getDataPath() {
|
||||
return this.dataPath;
|
||||
}
|
||||
|
||||
public String getTempDataPath() {
|
||||
return this.tempDataPath;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user