mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-1164: Reorganizing Ghidra's user settings/cache/temp directories to support XDG
This commit is contained in:
@@ -24,6 +24,7 @@ import db.Database;
|
||||
import db.buffers.BufferFileManager;
|
||||
import db.buffers.LocalManagedBufferFile;
|
||||
import generic.jar.ResourceFile;
|
||||
import ghidra.framework.Application;
|
||||
import ghidra.framework.store.FolderItem;
|
||||
import ghidra.framework.store.db.PackedDatabaseCache.CachedDB;
|
||||
import ghidra.framework.store.local.*;
|
||||
@@ -32,7 +33,6 @@ import ghidra.util.datastruct.WeakDataStructureFactory;
|
||||
import ghidra.util.datastruct.WeakSet;
|
||||
import ghidra.util.exception.*;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
import ghidra.util.task.TaskMonitorAdapter;
|
||||
import utilities.util.FileUtilities;
|
||||
|
||||
/**
|
||||
@@ -364,7 +364,7 @@ public class PackedDatabase extends Database {
|
||||
*/
|
||||
private static File createDBDir() throws IOException {
|
||||
|
||||
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
|
||||
File tmpDir = Application.getUserTempDirectory();
|
||||
int tries = 0;
|
||||
while (tries++ < 10) {
|
||||
File dir = new File(tmpDir, TEMPDB_DIR_PREFIX + getRandomString() + TEMPDB_DIR_EXT);
|
||||
@@ -620,7 +620,7 @@ public class PackedDatabase extends Database {
|
||||
InputStream itemIn = null;
|
||||
File tmpFile = null;
|
||||
try {
|
||||
tmpFile = File.createTempFile("pack", ".tmp");
|
||||
tmpFile = Application.createTempFile("pack", ".tmp");
|
||||
tmpFile.delete();
|
||||
dbh.saveAs(tmpFile, false, monitor);
|
||||
itemIn = new BufferedInputStream(new FileInputStream(tmpFile));
|
||||
@@ -838,7 +838,7 @@ public class PackedDatabase extends Database {
|
||||
*/
|
||||
public static void cleanupOldTempDatabases() {
|
||||
|
||||
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
|
||||
File tmpDir = Application.getUserTempDirectory();
|
||||
File[] tempDbs = tmpDir.listFiles((FileFilter) file -> {
|
||||
String name = file.getName();
|
||||
if (file.isDirectory()) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import db.DBHandle;
|
||||
import db.Database;
|
||||
import db.buffers.*;
|
||||
import ghidra.framework.Application;
|
||||
import ghidra.framework.store.local.ItemSerializer;
|
||||
import ghidra.util.exception.*;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
@@ -417,7 +418,8 @@ public class VersionedDatabase extends Database {
|
||||
else {
|
||||
BufferFile bf = openBufferFile(version, -1);
|
||||
try {
|
||||
File tmpFile = File.createTempFile("ghidra", LocalBufferFile.TEMP_FILE_EXT);
|
||||
File tmpFile =
|
||||
Application.createTempFile("ghidra", LocalBufferFile.TEMP_FILE_EXT);
|
||||
tmpFile.delete();
|
||||
BufferFile tmpBf = new LocalBufferFile(tmpFile, bf.getBufferSize());
|
||||
boolean success = false;
|
||||
@@ -425,18 +427,10 @@ public class VersionedDatabase extends Database {
|
||||
LocalBufferFile.copyFile(bf, tmpBf, null, monitor);
|
||||
tmpBf.close();
|
||||
|
||||
InputStream itemIn = new FileInputStream(tmpFile);
|
||||
try {
|
||||
try (InputStream itemIn = new FileInputStream(tmpFile)) {
|
||||
ItemSerializer.outputItem(name, contentType, filetype, tmpFile.length(),
|
||||
itemIn, outputFile, monitor);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
itemIn.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -18,6 +18,7 @@ package ghidra.framework.store.remote;
|
||||
import java.io.*;
|
||||
|
||||
import db.buffers.*;
|
||||
import ghidra.framework.Application;
|
||||
import ghidra.framework.client.RepositoryAdapter;
|
||||
import ghidra.framework.remote.RepositoryItem;
|
||||
import ghidra.framework.store.DatabaseItem;
|
||||
@@ -101,25 +102,17 @@ public class RemoteDatabaseItem extends RemoteFolderItem implements DatabaseItem
|
||||
|
||||
BufferFile bf = repository.openDatabase(parentPath, itemName, version, -1);
|
||||
try {
|
||||
File tmpFile = File.createTempFile("ghidra", LocalBufferFile.TEMP_FILE_EXT);
|
||||
File tmpFile = Application.createTempFile("ghidra", LocalBufferFile.TEMP_FILE_EXT);
|
||||
tmpFile.delete();
|
||||
BufferFile tmpBf = new LocalBufferFile(tmpFile, bf.getBufferSize());
|
||||
try {
|
||||
LocalBufferFile.copyFile(bf, tmpBf, null, monitor);
|
||||
tmpBf.close();
|
||||
|
||||
InputStream itemIn = new FileInputStream(tmpFile);
|
||||
try {
|
||||
try (InputStream itemIn = new FileInputStream(tmpFile)) {
|
||||
ItemSerializer.outputItem(getName(), getContentType(), DATABASE_FILE_TYPE,
|
||||
tmpFile.length(), itemIn, outputFile, monitor);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
itemIn.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
tmpBf.close();
|
||||
|
||||
Reference in New Issue
Block a user