diff options
author | drh <drh@noemail.net> | 2011-04-09 02:09:44 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2011-04-09 02:09:44 +0000 |
commit | 2b89fbcb1ecf6cdae61ecb4e7b6433801f7970ed (patch) | |
tree | 798edba61435068692da1d454588a1b30ebec32f /src/backup.c | |
parent | ea6dc4458b335a4fafd7d736c3e23f2e2e765ef8 (diff) | |
download | sqlite-2b89fbcb1ecf6cdae61ecb4e7b6433801f7970ed.tar.gz sqlite-2b89fbcb1ecf6cdae61ecb4e7b6433801f7970ed.zip |
Do not do a backup if the number of reserved bytes in the source and
destination do not match. Try to make the match, but if unable fail.
FossilOrigin-Name: 0ca8a2332b28d88585dc890e5162b095e783fc20
Diffstat (limited to 'src/backup.c')
-rw-r--r-- | src/backup.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/backup.c b/src/backup.c index c062744c5..5e45a0025 100644 --- a/src/backup.c +++ b/src/backup.c @@ -219,6 +219,10 @@ static int backupOnePage(sqlite3_backup *p, Pgno iSrcPg, const u8 *zSrcData){ int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest); const int nCopy = MIN(nSrcPgsz, nDestPgsz); const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz; +#ifdef SQLITE_HAS_CODEC + int nSrcReserve = sqlite3BtreeGetReserve(p->pSrc); + int nDestReserve = sqlite3BtreeGetReserve(p->pDest); +#endif int rc = SQLITE_OK; i64 iOff; @@ -237,11 +241,22 @@ static int backupOnePage(sqlite3_backup *p, Pgno iSrcPg, const u8 *zSrcData){ #ifdef SQLITE_HAS_CODEC /* Backup is not possible if the page size of the destination is changing - ** a a codec is in use. + ** and a codec is in use. */ if( nSrcPgsz!=nDestPgsz && sqlite3PagerGetCodec(pDestPager)!=0 ){ rc = SQLITE_READONLY; } + + /* Backup is not possible if the number of bytes of reserve space differ + ** between source and destination. If there is a difference, try to + ** fix the destination to agree with the source. If that is not possible, + ** then the backup cannot proceed. + */ + if( nSrcReserve!=nDestReserve ){ + u32 newPgsz = nSrcPgsz; + rc = sqlite3PagerSetPagesize(pDestPager, &newPgsz, nSrcReserve); + if( rc==SQLITE_OK && newPgsz!=nSrcPgsz ) rc = SQLITE_READONLY; + } #endif /* This loop runs once for each destination page spanned by the source @@ -607,7 +622,10 @@ void sqlite3BackupUpdate(sqlite3_backup *pBackup, Pgno iPage, const u8 *aData){ ** has been modified by a transaction on the source pager. Copy ** the new data into the backup. */ - int rc = backupOnePage(p, iPage, aData); + int rc; + if( p->pDestDb ) sqlite3_mutex_enter(p->pDestDb->mutex); + rc = backupOnePage(p, iPage, aData); + if( p->pDestDb ) sqlite3_mutex_leave(p->pDestDb->mutex); assert( rc!=SQLITE_BUSY && rc!=SQLITE_LOCKED ); if( rc!=SQLITE_OK ){ p->rc = rc; |