mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-14 00:22:38 +03:00
Make sure the antipenultimate character of master-journal filenames is a "9"
in order to avoid collisions with other files in 8+3 filename mode. Also, limit the number of attempts at finding a unique master-journal filename. FossilOrigin-Name: 34a0483605d36e6cf03065ed0df33fb1f7c8a272
This commit is contained in:
@@ -1824,16 +1824,26 @@ static int vdbeCommit(sqlite3 *db, Vdbe *p){
|
||||
sqlite3_file *pMaster = 0;
|
||||
i64 offset = 0;
|
||||
int res;
|
||||
int retryCount = 0;
|
||||
|
||||
/* Select a master journal file name */
|
||||
do {
|
||||
u32 iRandom;
|
||||
if( retryCount++>100 ){
|
||||
sqlite3_log(SQLITE_FULL, "cannot create a master journal filename");
|
||||
rc = SQLITE_FULL;
|
||||
break;
|
||||
}
|
||||
sqlite3DbFree(db, zMaster);
|
||||
sqlite3_randomness(sizeof(iRandom), &iRandom);
|
||||
zMaster = sqlite3MPrintf(db, "%s-mj%08X", zMainFile, iRandom&0x7fffffff);
|
||||
zMaster = sqlite3MPrintf(db, "%s-mj%06X9%02X", zMainFile,
|
||||
(iRandom>>8)&0xffffff, iRandom&0xff);
|
||||
if( !zMaster ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
/* The antipenultimate character of the master journal name must
|
||||
** be "9" to avoid name collisions when using 8+3 filenames. */
|
||||
assert( zMaster[strlen(zMaster)-3]=='9' );
|
||||
sqlite3FileSuffix3(zMainFile, zMaster);
|
||||
rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res);
|
||||
}while( rc==SQLITE_OK && res );
|
||||
|
||||
Reference in New Issue
Block a user