* @throws SqlJetException
*/
private void deleteMaster(String master) throws SqlJetException {
boolean master_open = false;
ISqlJetFile pMaster = null;
/* Contents of master journal file */
ISqlJetMemoryPointer zMasterJournal = null;
/* Size of master journal file */
int nMasterJournal;
try {
/*
* Open the master journal file exclusively in case some other
* process is running this routine also. Not that it makes too much
* difference.
*/
pMaster = fileSystem.open(new File(master), SqlJetFileType.MASTER_JOURNAL, SqlJetUtility
.of(SqlJetFileOpenPermission.READONLY));
master_open = true;
nMasterJournal = Long.valueOf(pMaster.fileSize()).intValue();
if (nMasterJournal > 0) {
/*
* Load the entire master journal file into space obtained from
* sqlite3_malloc() and pointed to by zMasterJournal.
*/
zMasterJournal = SqlJetUtility.allocatePtr(nMasterJournal);
pMaster.read(zMasterJournal, nMasterJournal, 0);
int nMasterPtr = 0;
while (nMasterPtr < nMasterJournal) {
int zMasterPtr = SqlJetUtility.strlen(zMasterJournal, nMasterPtr);
String zJournal = SqlJetUtility.toString(SqlJetUtility.pointer(zMasterJournal, nMasterPtr));
final File journalPath = new File(zJournal);
boolean exists = fileSystem.access(journalPath, SqlJetFileAccesPermission.EXISTS);
if (exists) {
/*
* One of the journals pointed to by the master journal
* exists. Open it and check if it points at the master
* journal. If so, return without deleting the master
* journal file.
*/
final ISqlJetFile pJournal = fileSystem.open(journalPath, SqlJetFileType.MAIN_JOURNAL,
SqlJetUtility.of(SqlJetFileOpenPermission.READONLY));
try {
final String readJournal = readMasterJournal(pJournal);
if (readJournal != null && readJournal.equals(master)) {
/*
* We have a match. Do not delete the master
* journal file.
*/
return;
}
} finally {
pJournal.close();
}
}
nMasterPtr += zMasterPtr + 1;
}
}