1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

When closing a WAL connection, attempt an exclusive lock on the database file. If the lock is obtained, checkpoint the database and delete the wal and wal-index files.

FossilOrigin-Name: c05e7dca172719f33e245c08d0c0e8ab47e5a537
This commit is contained in:
dan
2010-04-30 15:49:27 +00:00
parent 6045461eee
commit a7ad518ef0
3 changed files with 34 additions and 7 deletions

View File

@@ -785,8 +785,35 @@ int sqlite3WalClose(
){
int rc = SQLITE_OK;
if( pWal ){
int isDelete = 0; /* True to unlink wal and wal-index files */
/* If an EXCLUSIVE lock can be obtained on the database file (using the
** ordinary, rollback-mode locking methods, this guarantees that the
** connection associated with this log file is the only connection to
** the database. In this case checkpoint the database and unlink both
** the wal and wal-index files.
**
** The EXCLUSIVE lock is not released before returning.
*/
rc = sqlite3OsLock(pFd, SQLITE_LOCK_EXCLUSIVE);
if( rc==SQLITE_OK ){
rc = walCheckpoint(pWal, pFd, sync_flags, zBuf);
if( rc==SQLITE_OK ){
isDelete = 1;
}
walIndexUnmap(pWal);
}
pWal->pVfs->xShmClose(pWal->pWIndex);
sqlite3OsClose(pWal->pFd);
if( isDelete ){
int nWal;
char *zWal = &((char *)pWal->pFd)[pWal->pVfs->szOsFile];
sqlite3OsDelete(pWal->pVfs, zWal, 0);
nWal = sqlite3Strlen30(zWal);
memcpy(&zWal[nWal], "-index", 7);
pWal->pVfs->xShmDelete(pWal->pVfs, zWal);
}
sqlite3_free(pWal);
}
return rc;