mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-08-08 07:40:39 -09:00
GP-7113 Corrected ContentHandle.getChangeSet version handling
This commit is contained in:
@@ -93,10 +93,11 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
/**
|
||||
* <code>bfMgr</code> manages the various files associated with this buffer
|
||||
* file. When working with versioned files or when Save support is
|
||||
* required <code>bfMgr</code> must be set. The bufMgr will be null for
|
||||
* a read-only non-updateable file.
|
||||
* required <code>bfMgr</code> must be set. The openForUpdate will be false
|
||||
* for a read-only non-updateable file.
|
||||
*/
|
||||
private BufferFileManager bfMgr;
|
||||
private boolean openForUpdate = false;
|
||||
|
||||
/**
|
||||
* <code>checkinId</code> is the checkin ID needed by bfMgr when a new
|
||||
@@ -174,6 +175,7 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
}
|
||||
this.version = 1;
|
||||
this.bfMgr = bfManager;
|
||||
this.openForUpdate = true;
|
||||
this.checkinId = checkinId;
|
||||
}
|
||||
|
||||
@@ -191,6 +193,7 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
int minChangeDataVer, long checkinId) throws IOException {
|
||||
super(bfManager.getBufferFile(bfManager.getCurrentVersion()), true);
|
||||
this.bfMgr = bfManager;
|
||||
this.openForUpdate = true;
|
||||
this.version = bfManager.getCurrentVersion();
|
||||
this.minChangeDataVer = minChangeDataVer;
|
||||
this.checkinId = checkinId;
|
||||
@@ -200,7 +203,7 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
}
|
||||
|
||||
/**
|
||||
* Open an older version of an existing buffer file as read-only and NOT UPDATEABLE (bfMgr remains null).
|
||||
* Open an older version of an existing buffer file as read-only and NOT UPDATEABLE (openForUpdate remains false).
|
||||
* Version files must exist for all versions starting with the requested version.
|
||||
* These version files will be used in conjunction with the current buffer file
|
||||
* to emulate an older version buffer file.
|
||||
@@ -214,6 +217,7 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
public LocalManagedBufferFile(BufferFileManager bfManager, int version, int minChangeDataVer)
|
||||
throws IOException {
|
||||
super(bfManager.getBufferFile(bfManager.getCurrentVersion()), true);
|
||||
this.bfMgr = bfManager;
|
||||
this.version = version;
|
||||
this.minChangeDataVer = minChangeDataVer;
|
||||
int curVer = bfManager.getCurrentVersion();
|
||||
@@ -243,9 +247,6 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
|
||||
@Override
|
||||
public BufferFile getNextChangeDataFile(boolean getFirst) throws IOException {
|
||||
if (bfMgr == null) {
|
||||
return null;
|
||||
}
|
||||
if (getFirst || nextChangeDataVer == -1) {
|
||||
nextChangeDataVer = minChangeDataVer != -1 ? minChangeDataVer : (version - 1);
|
||||
}
|
||||
@@ -291,9 +292,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 +314,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 +359,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();
|
||||
@@ -369,8 +374,8 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
|
||||
super.setReadOnly();
|
||||
|
||||
if (bfMgr != null) {
|
||||
// TODO: This seems very hidden!
|
||||
if (openForUpdate) {
|
||||
openForUpdate = false;
|
||||
bfMgr.versionCreated(version, comment, checkinId);
|
||||
startPreSave();
|
||||
}
|
||||
@@ -380,8 +385,9 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
@Override
|
||||
public synchronized void close() throws IOException {
|
||||
|
||||
if (isClosed())
|
||||
if (isClosed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
stopPreSave(true);
|
||||
|
||||
@@ -406,7 +412,8 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
// NOTE: the above close will delete non-read-only files which were not committed
|
||||
}
|
||||
finally {
|
||||
if (bfMgr != null) {
|
||||
if (openForUpdate) {
|
||||
openForUpdate = false;
|
||||
if (comit) {
|
||||
bfMgr.versionCreated(version, comment, checkinId);
|
||||
}
|
||||
@@ -427,8 +434,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 {
|
||||
@@ -448,7 +456,8 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (bfMgr != null) {
|
||||
if (openForUpdate) {
|
||||
openForUpdate = false;
|
||||
bfMgr.updateEnded(checkinId);
|
||||
}
|
||||
}
|
||||
@@ -456,9 +465,6 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
}
|
||||
|
||||
private byte[] getForwardModMapData() throws IOException {
|
||||
if (bfMgr == null) {
|
||||
return null;
|
||||
}
|
||||
File mf = bfMgr.getChangeMapFile();
|
||||
if (mf == null || !mf.exists()) {
|
||||
return null;
|
||||
@@ -474,9 +480,6 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
|
||||
@Override
|
||||
public byte[] getForwardModMapData(int oldVersion) throws IOException {
|
||||
if (bfMgr == null) {
|
||||
return null;
|
||||
}
|
||||
if (oldVersion < 1 || oldVersion >= version) {
|
||||
throw new IOException("Invalid mod-map version requested: " + oldVersion);
|
||||
}
|
||||
@@ -694,6 +697,7 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
if (saveFile.renameFile(newFile)) {
|
||||
saveFile.version = newVersion;
|
||||
saveFile.bfMgr = bfMgr;
|
||||
saveFile.openForUpdate = true;
|
||||
saveFile.checkinId = checkinId;
|
||||
|
||||
if (saveChangeFile != null) {
|
||||
@@ -712,6 +716,7 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
if (!success) {
|
||||
saveFile.delete();
|
||||
}
|
||||
|
||||
saveFile = null;
|
||||
saveChangeFile = null;
|
||||
}
|
||||
@@ -771,7 +776,7 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
||||
|
||||
synchronized (this) {
|
||||
// If preSaveFile is null and !preSaveFailed - we were unsuccessful at terminating the pre-save
|
||||
if (endUpdate && bfMgr != null && (preSaveFailed || preSaveFile != null)) {
|
||||
if (endUpdate && openForUpdate && (preSaveFailed || preSaveFile != null)) {
|
||||
|
||||
// Update is ended when we can no longer perform a save
|
||||
bfMgr.updateEnded(checkinId);
|
||||
@@ -1066,15 +1071,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);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user