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
|
* <code>bfMgr</code> manages the various files associated with this buffer
|
||||||
* file. When working with versioned files or when Save support is
|
* file. When working with versioned files or when Save support is
|
||||||
* required <code>bfMgr</code> must be set. The bufMgr will be null for
|
* required <code>bfMgr</code> must be set. The openForUpdate will be false
|
||||||
* a read-only non-updateable file.
|
* for a read-only non-updateable file.
|
||||||
*/
|
*/
|
||||||
private BufferFileManager bfMgr;
|
private BufferFileManager bfMgr;
|
||||||
|
private boolean openForUpdate = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>checkinId</code> is the checkin ID needed by bfMgr when a new
|
* <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.version = 1;
|
||||||
this.bfMgr = bfManager;
|
this.bfMgr = bfManager;
|
||||||
|
this.openForUpdate = true;
|
||||||
this.checkinId = checkinId;
|
this.checkinId = checkinId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,6 +193,7 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
int minChangeDataVer, long checkinId) throws IOException {
|
int minChangeDataVer, long checkinId) throws IOException {
|
||||||
super(bfManager.getBufferFile(bfManager.getCurrentVersion()), true);
|
super(bfManager.getBufferFile(bfManager.getCurrentVersion()), true);
|
||||||
this.bfMgr = bfManager;
|
this.bfMgr = bfManager;
|
||||||
|
this.openForUpdate = true;
|
||||||
this.version = bfManager.getCurrentVersion();
|
this.version = bfManager.getCurrentVersion();
|
||||||
this.minChangeDataVer = minChangeDataVer;
|
this.minChangeDataVer = minChangeDataVer;
|
||||||
this.checkinId = checkinId;
|
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.
|
* 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
|
* These version files will be used in conjunction with the current buffer file
|
||||||
* to emulate an older version 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)
|
public LocalManagedBufferFile(BufferFileManager bfManager, int version, int minChangeDataVer)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
super(bfManager.getBufferFile(bfManager.getCurrentVersion()), true);
|
super(bfManager.getBufferFile(bfManager.getCurrentVersion()), true);
|
||||||
|
this.bfMgr = bfManager;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.minChangeDataVer = minChangeDataVer;
|
this.minChangeDataVer = minChangeDataVer;
|
||||||
int curVer = bfManager.getCurrentVersion();
|
int curVer = bfManager.getCurrentVersion();
|
||||||
@@ -243,9 +247,6 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BufferFile getNextChangeDataFile(boolean getFirst) throws IOException {
|
public BufferFile getNextChangeDataFile(boolean getFirst) throws IOException {
|
||||||
if (bfMgr == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (getFirst || nextChangeDataVer == -1) {
|
if (getFirst || nextChangeDataVer == -1) {
|
||||||
nextChangeDataVer = minChangeDataVer != -1 ? minChangeDataVer : (version - 1);
|
nextChangeDataVer = minChangeDataVer != -1 ? minChangeDataVer : (version - 1);
|
||||||
}
|
}
|
||||||
@@ -291,9 +292,10 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
@Override
|
@Override
|
||||||
public synchronized DataBuffer get(DataBuffer buf, int index) throws IOException {
|
public synchronized DataBuffer get(DataBuffer buf, int index) throws IOException {
|
||||||
|
|
||||||
if (index > getBufferCount())
|
if (index > getBufferCount()) {
|
||||||
throw new EOFException(
|
throw new EOFException(
|
||||||
"Buffer index too large (" + index + " > " + getBufferCount() + ")");
|
"Buffer index too large (" + index + " > " + getBufferCount() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
if (versionFileHandler != null) {
|
if (versionFileHandler != null) {
|
||||||
DataBuffer vbuf = versionFileHandler.getOldBuffer(buf, index);
|
DataBuffer vbuf = versionFileHandler.getOldBuffer(buf, index);
|
||||||
@@ -312,10 +314,12 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
@Override
|
@Override
|
||||||
public synchronized void put(DataBuffer buf, int index) throws IOException {
|
public synchronized void put(DataBuffer buf, int index) throws IOException {
|
||||||
|
|
||||||
if (isReadOnly())
|
if (isReadOnly()) {
|
||||||
throw new IOException("File is read-only");
|
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");
|
throw new EOFException("Buffer index too large, exceeds max-int");
|
||||||
|
}
|
||||||
|
|
||||||
versionBufferIfNeeded(index);
|
versionBufferIfNeeded(index);
|
||||||
|
|
||||||
@@ -355,8 +359,9 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
@Override
|
@Override
|
||||||
public synchronized boolean setReadOnly() throws IOException {
|
public synchronized boolean setReadOnly() throws IOException {
|
||||||
|
|
||||||
if (!flush())
|
if (!flush()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (versionOutFile != null) {
|
if (versionOutFile != null) {
|
||||||
versionOutFile.close();
|
versionOutFile.close();
|
||||||
@@ -369,8 +374,8 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
|
|
||||||
super.setReadOnly();
|
super.setReadOnly();
|
||||||
|
|
||||||
if (bfMgr != null) {
|
if (openForUpdate) {
|
||||||
// TODO: This seems very hidden!
|
openForUpdate = false;
|
||||||
bfMgr.versionCreated(version, comment, checkinId);
|
bfMgr.versionCreated(version, comment, checkinId);
|
||||||
startPreSave();
|
startPreSave();
|
||||||
}
|
}
|
||||||
@@ -380,8 +385,9 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
@Override
|
@Override
|
||||||
public synchronized void close() throws IOException {
|
public synchronized void close() throws IOException {
|
||||||
|
|
||||||
if (isClosed())
|
if (isClosed()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
stopPreSave(true);
|
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
|
// NOTE: the above close will delete non-read-only files which were not committed
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (bfMgr != null) {
|
if (openForUpdate) {
|
||||||
|
openForUpdate = false;
|
||||||
if (comit) {
|
if (comit) {
|
||||||
bfMgr.versionCreated(version, comment, checkinId);
|
bfMgr.versionCreated(version, comment, checkinId);
|
||||||
}
|
}
|
||||||
@@ -427,8 +434,9 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
@Override
|
@Override
|
||||||
public synchronized boolean delete() {
|
public synchronized boolean delete() {
|
||||||
|
|
||||||
if (isClosed() || isReadOnly())
|
if (isClosed() || isReadOnly()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
@@ -448,7 +456,8 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (bfMgr != null) {
|
if (openForUpdate) {
|
||||||
|
openForUpdate = false;
|
||||||
bfMgr.updateEnded(checkinId);
|
bfMgr.updateEnded(checkinId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -456,9 +465,6 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
}
|
}
|
||||||
|
|
||||||
private byte[] getForwardModMapData() throws IOException {
|
private byte[] getForwardModMapData() throws IOException {
|
||||||
if (bfMgr == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
File mf = bfMgr.getChangeMapFile();
|
File mf = bfMgr.getChangeMapFile();
|
||||||
if (mf == null || !mf.exists()) {
|
if (mf == null || !mf.exists()) {
|
||||||
return null;
|
return null;
|
||||||
@@ -474,9 +480,6 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getForwardModMapData(int oldVersion) throws IOException {
|
public byte[] getForwardModMapData(int oldVersion) throws IOException {
|
||||||
if (bfMgr == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (oldVersion < 1 || oldVersion >= version) {
|
if (oldVersion < 1 || oldVersion >= version) {
|
||||||
throw new IOException("Invalid mod-map version requested: " + oldVersion);
|
throw new IOException("Invalid mod-map version requested: " + oldVersion);
|
||||||
}
|
}
|
||||||
@@ -694,6 +697,7 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
if (saveFile.renameFile(newFile)) {
|
if (saveFile.renameFile(newFile)) {
|
||||||
saveFile.version = newVersion;
|
saveFile.version = newVersion;
|
||||||
saveFile.bfMgr = bfMgr;
|
saveFile.bfMgr = bfMgr;
|
||||||
|
saveFile.openForUpdate = true;
|
||||||
saveFile.checkinId = checkinId;
|
saveFile.checkinId = checkinId;
|
||||||
|
|
||||||
if (saveChangeFile != null) {
|
if (saveChangeFile != null) {
|
||||||
@@ -712,6 +716,7 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
if (!success) {
|
if (!success) {
|
||||||
saveFile.delete();
|
saveFile.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
saveFile = null;
|
saveFile = null;
|
||||||
saveChangeFile = null;
|
saveChangeFile = null;
|
||||||
}
|
}
|
||||||
@@ -771,7 +776,7 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// If preSaveFile is null and !preSaveFailed - we were unsuccessful at terminating the pre-save
|
// 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
|
// Update is ended when we can no longer perform a save
|
||||||
bfMgr.updateEnded(checkinId);
|
bfMgr.updateEnded(checkinId);
|
||||||
@@ -1066,15 +1071,20 @@ public class LocalManagedBufferFile extends LocalBufferFile implements ManagedBu
|
|||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
saveCompleted(success);
|
try {
|
||||||
if (!success) {
|
saveCompleted(success);
|
||||||
bfMgr.updateEnded(checkinId);
|
}
|
||||||
|
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