Skip to content

Ghidra is a software reverse engineering (SRE) framework

Test fixes

dragonmacher45c307ab4cde
diff --git a/Ghidra/Features/Base/src/test/java/ghidra/base/project/FakeSharedProject.java b/Ghidra/Features/Base/src/test/java/ghidra/base/project/FakeSharedProject.java
index 19d0b7b246..71ae44f2c3 100644
--- a/Ghidra/Features/Base/src/test/java/ghidra/base/project/FakeSharedProject.java
+++ b/Ghidra/Features/Base/src/test/java/ghidra/base/project/FakeSharedProject.java
@@ -20,6 +20,7 @@ import static generic.test.AbstractGenericTest.invokeInstanceMethod;
import static generic.test.TestUtils.*;
import static org.junit.Assert.*;
+import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
@@ -36,6 +37,7 @@ import ghidra.framework.store.local.LocalFileSystem;
import ghidra.program.model.listing.Program;
import ghidra.test.TestEnv;
import ghidra.test.TestProgramManager;
+import ghidra.util.Msg;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
import utilities.util.FileUtilities;
@@ -378,9 +380,26 @@ public class FakeSharedProject {
public void dispose() {
ProjectLocator projectLocator = getProjectData().getProjectLocator();
programManager.disposeOpenPrograms();
+
+ String projectName = gProject.getProject().getName();
gProject.close();
- FileUtilities.deleteDir(projectLocator.getProjectDir());
- projectLocator.getMarkerFile().delete();
+
+ File projectDir = projectLocator.getProjectDir();
+ if (projectDir.exists()) {
+ boolean success = FileUtilities.deleteDir(projectDir);
+ if (!success) {
+ Msg.error(this, "Unable to delete test project dir '%s' in %s".formatted(projectName, projectDir));
+ }
+ }
+
+
+ File markerFile = projectLocator.getMarkerFile();
+ if (markerFile.exists()) {
+ boolean success = markerFile.delete();
+ if (!success) {
+ Msg.error(this, "Unable to delete test project marker file: " + markerFile);
+ }
+ }
}
@Override
diff --git a/Ghidra/Framework/DB/src/main/java/db/buffers/LocalManagedBufferFile.java b/Ghidra/Framework/DB/src/main/java/db/buffers/LocalManagedBufferFile.java
index 7d82990e81..e597cca2df 100644
--- a/Ghidra/Framework/DB/src/main/java/db/buffers/LocalManagedBufferFile.java
+++ b/Ghidra/Framework/DB/src/main/java/db/buffers/LocalManagedBufferFile.java
@@ -291,9 +291,10 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
@Override
public synchronized DataBuffer get(DataBuffer buf, int index) throws IOException {
- if (index > getBufferCount())
+ if (index > getBufferCount()) {
throw new EOFException(
"Buffer index too large (" + index + " > " + getBufferCount() + ")");
+ }
if (versionFileHandler != null) {
DataBuffer vbuf = versionFileHandler.getOldBuffer(buf, index);
@@ -312,10 +313,12 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
@Override
public synchronized void put(DataBuffer buf, int index) throws IOException {
- if (isReadOnly())
+ if (isReadOnly()) {
throw new IOException("File is read-only");
- if (index > MAX_BUFFER_INDEX)
+ }
+ if (index > MAX_BUFFER_INDEX) {
throw new EOFException("Buffer index too large, exceeds max-int");
+ }
versionBufferIfNeeded(index);
@@ -355,8 +358,9 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
@Override
public synchronized boolean setReadOnly() throws IOException {
- if (!flush())
+ if (!flush()) {
return false;
+ }
if (versionOutFile != null) {
versionOutFile.close();
@@ -380,8 +384,9 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
@Override
public synchronized void close() throws IOException {
- if (isClosed())
+ if (isClosed()) {
return;
+ }
stopPreSave(true);
@@ -427,8 +432,9 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
@Override
public synchronized boolean delete() {
- if (isClosed() || isReadOnly())
+ if (isClosed() || isReadOnly()) {
return false;
+ }
boolean success = false;
try {
@@ -712,6 +718,7 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
if (!success) {
saveFile.delete();
}
+
saveFile = null;
saveChangeFile = null;
}
@@ -1066,15 +1073,20 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
success = true;
}
finally {
- saveCompleted(success);
- if (!success) {
- bfMgr.updateEnded(checkinId);
+ try {
+ saveCompleted(success);
+ }
+ finally {
+ bf.dispose();
+ if (!success) {
+ bfMgr.updateEnded(checkinId);
+ }
+// else {
+// // VERIFY RESULT FILE
+// System.err.println("Update check: " + file);
+// checkSameContent(versionedBufferFile, bf);
+// }
}
-// else {
-// // VERIFY RESULT FILE
-// System.err.println("Update check: " + file);
-// checkSameContent(versionedBufferFile, bf);
-// }
}
}