-C Add\sthe\soptional\s(and\sexperimental)\smmap()\smemory\sallocator\sin\sthe\nmem4.c\smodule.\s(CVS\s4581)
-D 2007-11-29T18:36:49
+C Make\ssure\swe\snever\stry\sto\s"truncate"\sa\sfile\sto\sa\slarger\ssize.\s(CVS\s4582)
+D 2007-11-29T18:44:27
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in d9419c71360931f0711d572e06f726f29656bfc3
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c 1fb40eb62fb0719ea578d69edcb1a2974f04d214
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
-F src/pager.c bb524fe4b501a60762d07d6d0d33fd548b176cf6
+F src/pager.c 65298fee4e815c269fb374d3fe3cd1cf4f05ad94
F src/pager.h f504f7ae84060fee0416a853e368d3d113c3d6fa
F src/parse.y a780b33ef45dd7b3272319cf91e609d6f109a31c
F src/pragma.c cb1486e76dbcad757968afc4083d3472032e62b5
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 061608c72ac0a96eacf3b64d638235e4739f96ba
-R 1c1c1bbe1258e7de094daae06d9ba74e
+P cfd683ac80fd043343e0f0af90805058daa3818d
+R efe61aec0ac9fa4f2be861c956b27113
U drh
-Z 1c04b0f4f3c446511a85e32381699825
+Z fd3607ea80d91b437bccfba278c95b97
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.396 2007/11/28 16:19:56 drh Exp $
+** @(#) $Id: pager.c,v 1.397 2007/11/29 18:44:27 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
/*
** Truncate the main file of the given pager to the number of pages
** indicated. Also truncate the cached representation of the file.
+**
+** Might might be the case that the file on disk is smaller than nPage.
+** This can happen, for example, if we are in the middle of a transaction
+** which has extended the file size and the new pages are still all held
+** in cache, then an INSERT or UPDATE does a statement rollback. Some
+** operating system implementations can get confused if you try to
+** truncate a file to some size that is larger than it currently is,
+** so detect this case and do not do the truncation.
*/
static int pager_truncate(Pager *pPager, int nPage){
int rc = SQLITE_OK;
if( pPager->state>=PAGER_EXCLUSIVE && pPager->fd->pMethods ){
- rc = sqlite3OsTruncate(pPager->fd, pPager->pageSize*(i64)nPage);
+ i64 currentSize, newSize;
+ rc = sqlite3OsFileSize(pPager->fd, ¤tSize);
+ newSize = pPager->pageSize*(i64)nPage;
+ if( rc==SQLITE_OK && currentSize>newSize ){
+ rc = sqlite3OsTruncate(pPager->fd, newSize);
+ }
}
if( rc==SQLITE_OK ){
pPager->dbSize = nPage;