1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Add code to detect if the database file is moved or deleted out from under

SQLite and return an SQLITE_IOERR_NODB.

FossilOrigin-Name: 8759a8e4d83b163e315eff316cf163f6ea42f2bb
This commit is contained in:
drh
2013-12-06 15:37:35 +00:00
parent 6f04b95f02
commit 1b1f30bb5e
7 changed files with 84 additions and 15 deletions

View File

@@ -4797,6 +4797,27 @@ int sqlite3PagerOpen(
}
/* Verify that the database file has not be deleted or renamed out from
** under the pager. Return SQLITE_OK if the database is still were it ought
** to be on disk. Return non-zero (SQLITE_IOERR_NODB or some other error
** code from sqlite3OsAccess()) if the database has gone missing.
*/
static int databaseIsUnmoved(Pager *pPager){
const int fixedFlags = SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
SQLITE_IOCAP_UNMOVABLE_WHEN_OPEN;
int dc;
int x = 0, rc;
if( pPager->tempFile ) return SQLITE_OK;
if( pPager->dbSize==0 ) return SQLITE_OK;
assert( pPager->zFilename && pPager->zFilename[0] );
dc = sqlite3OsDeviceCharacteristics(pPager->fd);
if( (dc&fixedFlags)==fixedFlags ) return SQLITE_OK;
rc = sqlite3OsAccess(pPager->pVfs, pPager->zFilename, SQLITE_ACCESS_EXISTS, &x);
if( rc==SQLITE_OK && !x ) rc = SQLITE_IOERR_NODB;
return rc;
}
/*
** This function is called after transitioning from PAGER_UNLOCK to
@@ -4970,6 +4991,10 @@ int sqlite3PagerSharedLock(Pager *pPager){
goto failed;
}
/* Verify that the database is unmoved and undeleted */
rc = databaseIsUnmoved(pPager);
if( rc ) goto failed;
/* If a journal file exists, and there is no RESERVED lock on the
** database file, then it either needs to be played back or deleted.
*/