Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Update multiplex VFS to handle empty filenames which can occur for during vacuuming (temp file names.) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
a074986045f1a81fb831ffee4a29af13 |
User & Date: | shaneh 2011-05-18 02:22:41.100 |
Context
2011-05-18
| ||
02:41 | Remove unreachable branches from the 8.3 filename logic. (check-in: 4f7e7b44f2 user: drh tags: trunk) | |
02:22 | Update multiplex VFS to handle empty filenames which can occur for during vacuuming (temp file names.) (check-in: a074986045 user: shaneh tags: trunk) | |
2011-05-17
| ||
20:36 | Add the ability to limit filenames to 8+3 using the SQLITE_ENABLE_8_3_NAMES compile-time option together with a URI parameter of "8_3_names=1". (check-in: 96d6098560 user: drh tags: trunk) | |
Changes
Changes to src/test_multiplex.c.
︙ | ︙ | |||
181 182 183 184 185 186 187 | ** Compute a string length that is limited to what can be stored in ** lower 30 bits of a 32-bit signed integer. ** ** The value returned will never be negative. Nor will it ever be greater ** than the actual length of the string. For very long strings (greater ** than 1GiB) the value returned might be less than the true string length. */ | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | ** Compute a string length that is limited to what can be stored in ** lower 30 bits of a 32-bit signed integer. ** ** The value returned will never be negative. Nor will it ever be greater ** than the actual length of the string. For very long strings (greater ** than 1GiB) the value returned might be less than the true string length. */ static int multiplexStrlen30(const char *z){ const char *z2 = z; if( z==0 ) return 0; while( *z2 ){ z2++; } return 0x3fffffff & (int)(z2 - z); } /* ** Create a temporary file name in zBuf. zBuf must be big enough to ** hold at pOrigVfs->mxPathname characters. This function departs ** from the traditional temporary name generation in the os_win ** and os_unix VFS in several ways, but is necessary so that ** the file name is known for temporary files (like those used ** during vacuum.) ** ** N.B. This routine assumes your underlying VFS is ok with using ** "/" as a directory seperator. This is the default for UNIXs ** and is allowed (even mixed) for most versions of Windows. */ static int multiplexGetTempname(sqlite3_vfs *pOrigVfs, int nBuf, char *zBuf){ static char zChars[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; int i,j; int attempts = 0; int exists = 0; int rc = SQLITE_ERROR; /* Check that the output buffer is large enough for ** pVfs->mxPathname characters. */ if( pOrigVfs->mxPathname <= nBuf ){ /* sqlite3_temp_directory should always be less than ** pVfs->mxPathname characters. */ sqlite3_snprintf(pOrigVfs->mxPathname, zBuf, "%s/", sqlite3_temp_directory ? sqlite3_temp_directory : "."); /* Check that the output buffer is large enough for the temporary file ** name. */ j = multiplexStrlen30(zBuf); if( (j + 8 + 1 + 3 + 1) <= nBuf ){ /* Make 3 attempts to generate a unique name. */ do { attempts++; sqlite3_randomness(8, &zBuf[j]); for(i=0; i<8; i++){ zBuf[j+i] = (char)zChars[ ((unsigned char)zBuf[j+i])%(sizeof(zChars)-1) ]; } memcpy(&zBuf[j+i], ".tmp", 5); rc = pOrigVfs->xAccess(pOrigVfs, zBuf, SQLITE_ACCESS_EXISTS, &exists); } while ( (rc==SQLITE_OK) && exists && (attempts<3) ); if( rc==SQLITE_OK && exists ){ rc = SQLITE_ERROR; } } } return rc; } /* Translate an sqlite3_file* that is really a multiplexGroup* into ** the sqlite3_file* for the underlying original VFS. */ static sqlite3_file *multiplexSubOpen(multiplexConn *pConn, int iChunk, int *rc, int *pOutFlags){ multiplexGroup *pGroup = pConn->pGroup; sqlite3_vfs *pOrigVfs = gMultiplex.pOrigVfs; /* Real VFS */ |
︙ | ︙ | |||
291 292 293 294 295 296 297 | static int multiplexOpen( sqlite3_vfs *pVfs, /* The multiplex VFS */ const char *zName, /* Name of file to be opened */ sqlite3_file *pConn, /* Fill in this file descriptor */ int flags, /* Flags to control the opening */ int *pOutFlags /* Flags showing results of opening */ ){ | | | > > > > > > > > > > > > | > | | | | | | | | | | | | > > | > | 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | static int multiplexOpen( sqlite3_vfs *pVfs, /* The multiplex VFS */ const char *zName, /* Name of file to be opened */ sqlite3_file *pConn, /* Fill in this file descriptor */ int flags, /* Flags to control the opening */ int *pOutFlags /* Flags showing results of opening */ ){ int rc = SQLITE_OK; /* Result code */ multiplexConn *pMultiplexOpen; /* The new multiplex file descriptor */ multiplexGroup *pGroup; /* Corresponding multiplexGroup object */ sqlite3_file *pSubOpen; /* Real file descriptor */ sqlite3_vfs *pOrigVfs = gMultiplex.pOrigVfs; /* Real VFS */ int nName; int i; int sz; UNUSED_PARAMETER(pVfs); /* We need to create a group structure and manage ** access to this group of files. */ multiplexEnter(); pMultiplexOpen = (multiplexConn*)pConn; /* If the second argument to this function is NULL, generate a ** temporary file name to use. This will be handled by the ** original xOpen method. We just need to allocate space for ** it. */ if( !zName ){ rc = multiplexGetTempname(pOrigVfs, pOrigVfs->mxPathname, gMultiplex.zName); zName = gMultiplex.zName; } if( rc==SQLITE_OK ){ /* allocate space for group */ nName = multiplexStrlen30(zName); sz = sizeof(multiplexGroup) /* multiplexGroup */ + (sizeof(sqlite3_file *)*SQLITE_MULTIPLEX_MAX_CHUNKS) /* pReal[] */ + (pOrigVfs->szOsFile*SQLITE_MULTIPLEX_MAX_CHUNKS) /* *pReal */ + SQLITE_MULTIPLEX_MAX_CHUNKS /* bOpen[] */ + nName + 1; /* zName */ #ifndef SQLITE_MULTIPLEX_EXT_OVWR sz += SQLITE_MULTIPLEX_EXT_SZ; assert(nName+SQLITE_MULTIPLEX_EXT_SZ < pOrigVfs->mxPathname); #else assert(nName >= SQLITE_MULTIPLEX_EXT_SZ); assert(nName < pOrigVfs->mxPathname); #endif pGroup = sqlite3_malloc( sz ); if( pGroup==0 ){ rc=SQLITE_NOMEM; } } if( rc==SQLITE_OK ){ /* assign pointers to extra space allocated */ char *p = (char *)&pGroup[1]; pMultiplexOpen->pGroup = pGroup; memset(pGroup, 0, sz); pGroup->bEnabled = -1; pGroup->nChunkSize = SQLITE_MULTIPLEX_CHUNK_SIZE; pGroup->nMaxChunks = SQLITE_MULTIPLEX_MAX_CHUNKS; |
︙ | ︙ | |||
407 408 409 410 411 412 413 | sqlite3_snprintf(SQLITE_MULTIPLEX_EXT_SZ+1, gMultiplex.zName+nName, SQLITE_MULTIPLEX_EXT_FMT, i); #endif } rc2 = pOrigVfs->xAccess(pOrigVfs, gMultiplex.zName, SQLITE_ACCESS_EXISTS, &exists); | | | 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | sqlite3_snprintf(SQLITE_MULTIPLEX_EXT_SZ+1, gMultiplex.zName+nName, SQLITE_MULTIPLEX_EXT_FMT, i); #endif } rc2 = pOrigVfs->xAccess(pOrigVfs, gMultiplex.zName, SQLITE_ACCESS_EXISTS, &exists); if( rc2==SQLITE_OK && exists ){ /* if it exists, delete it */ rc2 = pOrigVfs->xDelete(pOrigVfs, gMultiplex.zName, syncDir); if( rc2!=SQLITE_OK ) rc = rc2; }else{ /* stop at first "gap" */ break; } |
︙ | ︙ |
Changes to test/multiplex.test.
︙ | ︙ | |||
562 563 564 565 566 567 568 569 570 571 | } } {1 {disk I/O error}} do_test multiplex-5.6.4.$jmode { db close } {} } } catch { sqlite3_multiplex_shutdown } finish_test | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | } } {1 {disk I/O error}} do_test multiplex-5.6.4.$jmode { db close } {} } } #------------------------------------------------------------------------- # Test that you can vacuum a multiplex'ed DB. ifcapable vacuum { do_test multiplex-6.0.0 { multiplex_delete test.db sqlite3_multiplex_initialize "" 1 sqlite3 db test.db multiplex_set db main 4096 16 } {SQLITE_OK} do_test multiplex-6.1.0 { execsql { PRAGMA page_size=1024; PRAGMA journal_mode=DELETE; PRAGMA auto_vacuum=OFF; } execsql { CREATE TABLE t1(a, b); INSERT INTO t1 VALUES(1, randomblob($g_chunk_size)); INSERT INTO t1 VALUES(2, randomblob($g_chunk_size)); } } {} do_test multiplex-6.2.1 { file size [multiplex_name test.db 0] } [list $g_chunk_size] do_test multiplex-6.2.2 { file size [multiplex_name test.db 1] } [list $g_chunk_size] do_test multiplex-6.3.0 { execsql { VACUUM } } {} do_test multiplex-6.99 { db close multiplex_delete test.db sqlite3_multiplex_shutdown } {SQLITE_OK} } catch { sqlite3_multiplex_shutdown } finish_test |