1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-15 11:41:13 +03:00

Replicate asserts on unixOpen() to winOpen() in os_win.c.

FossilOrigin-Name: 40526d8390896ccb883c45afa70e7adb568d174f
This commit is contained in:
shaneh
2010-08-24 20:46:53 +00:00
parent 9091f775a8
commit f7b5f855d7
3 changed files with 77 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
C Changes\sto\ssupport\sbuilding\swith\sSQLITE_OMIT_WAL. C Replicate\sasserts\son\sunixOpen()\sto\swinOpen()\sin\sos_win.c.
D 2010-08-24T18:35:12 D 2010-08-24T20:46:53
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 543f91f24cd7fee774ecc0a61c19704c0c3e78fd F Makefile.in 543f91f24cd7fee774ecc0a61c19704c0c3e78fd
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -155,7 +155,7 @@ F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9
F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
F src/os_os2.c 72d0b2e562952a2464308c4ce5f7913ac10bef3e F src/os_os2.c 72d0b2e562952a2464308c4ce5f7913ac10bef3e
F src/os_unix.c 11194cbcf6a57456e58022dc537ab8c3497d9bb9 F src/os_unix.c 11194cbcf6a57456e58022dc537ab8c3497d9bb9
F src/os_win.c 51cb62f76262d961ea4249489383d714501315a7 F src/os_win.c 718a48ca09d1bb747acb6b76e6a7e20eab182a7e
F src/pager.c 48556db031d16064ffbde48053da8ec5032df7e8 F src/pager.c 48556db031d16064ffbde48053da8ec5032df7e8
F src/pager.h ef8c8f71ab022cc2fff768a1175dd32355be9dcd F src/pager.h ef8c8f71ab022cc2fff768a1175dd32355be9dcd
F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58 F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
@@ -846,7 +846,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 5e8101c5122336844ea920e6fbdace23e35b931f P d1ed743b6ed07ad0ee7d466932c5a83caa9489ee
R a696c1133501b0d7ad2be0304e78dcd5 R 4de3851ce739f58f5ec292f30759a537
U shaneh U shaneh
Z 80d9d8f470083fca9ed888138d87f8b3 Z b2eb9e260c96bf7904a512bfdbfae9ac

View File

@@ -1 +1 @@
d1ed743b6ed07ad0ee7d466932c5a83caa9489ee 40526d8390896ccb883c45afa70e7adb568d174f

View File

@@ -1468,7 +1468,7 @@ static int winOpenSharedMemory(winFile *pDbFd){
rc = winOpen(pDbFd->pVfs, rc = winOpen(pDbFd->pVfs,
pShmNode->zFilename, /* Name of the file (UTF-8) */ pShmNode->zFilename, /* Name of the file (UTF-8) */
(sqlite3_file*)&pShmNode->hFile, /* File handle here */ (sqlite3_file*)&pShmNode->hFile, /* File handle here */
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */ SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */
0); 0);
if( SQLITE_OK!=rc ){ if( SQLITE_OK!=rc ){
rc = SQLITE_CANTOPEN_BKPT; rc = SQLITE_CANTOPEN_BKPT;
@@ -2024,9 +2024,54 @@ static int winOpen(
int isTemp = 0; int isTemp = 0;
#endif #endif
winFile *pFile = (winFile*)id; winFile *pFile = (winFile*)id;
void *zConverted; /* Filename in OS encoding */ void *zConverted; /* Filename in OS encoding */
const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */ const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
char zTmpname[MAX_PATH+1]; /* Buffer used to create temp filename */
/* If argument zPath is a NULL pointer, this function is required to open
** a temporary file. Use this buffer to store the file name in.
*/
char zTmpname[MAX_PATH+1]; /* Buffer used to create temp filename */
int rc = SQLITE_OK; /* Function Return Code */
int eType = flags&0xFFFFFF00; /* Type of file to open */
int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE);
int isCreate = (flags & SQLITE_OPEN_CREATE);
int isReadonly = (flags & SQLITE_OPEN_READONLY);
int isReadWrite = (flags & SQLITE_OPEN_READWRITE);
int isOpenJournal = (isCreate && (
eType==SQLITE_OPEN_MASTER_JOURNAL
|| eType==SQLITE_OPEN_MAIN_JOURNAL
|| eType==SQLITE_OPEN_WAL
));
/* Check the following statements are true:
**
** (a) Exactly one of the READWRITE and READONLY flags must be set, and
** (b) if CREATE is set, then READWRITE must also be set, and
** (c) if EXCLUSIVE is set, then CREATE must also be set.
** (d) if DELETEONCLOSE is set, then CREATE must also be set.
*/
assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
assert(isCreate==0 || isReadWrite);
assert(isExclusive==0 || isCreate);
assert(isDelete==0 || isCreate);
/* The main DB, main journal, WAL file and master journal are never
** automatically deleted. Nor are they ever temporary files. */
assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL );
assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
/* Assert that the upper layer has set one of the "file-type" flags. */
assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
|| eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
|| eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
|| eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
);
assert( id!=0 ); assert( id!=0 );
UNUSED_PARAMETER(pVfs); UNUSED_PARAMETER(pVfs);
@@ -2037,7 +2082,8 @@ static int winOpen(
** temporary file name to use ** temporary file name to use
*/ */
if( !zUtf8Name ){ if( !zUtf8Name ){
int rc = getTempname(MAX_PATH+1, zTmpname); assert(isDelete && !isOpenJournal);
rc = getTempname(MAX_PATH+1, zTmpname);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
return rc; return rc;
} }
@@ -2050,29 +2096,31 @@ static int winOpen(
return SQLITE_NOMEM; return SQLITE_NOMEM;
} }
if( flags & SQLITE_OPEN_READWRITE ){ if( isReadWrite ){
dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
}else{ }else{
dwDesiredAccess = GENERIC_READ; dwDesiredAccess = GENERIC_READ;
} }
/* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
** created. SQLite doesn't use it to indicate "exclusive access" ** created. SQLite doesn't use it to indicate "exclusive access"
** as it is usually understood. ** as it is usually understood.
*/ */
assert(!(flags & SQLITE_OPEN_EXCLUSIVE) || (flags & SQLITE_OPEN_CREATE)); if( isExclusive ){
if( flags & SQLITE_OPEN_EXCLUSIVE ){
/* Creates a new file, only if it does not already exist. */ /* Creates a new file, only if it does not already exist. */
/* If the file exists, it fails. */ /* If the file exists, it fails. */
dwCreationDisposition = CREATE_NEW; dwCreationDisposition = CREATE_NEW;
}else if( flags & SQLITE_OPEN_CREATE ){ }else if( isCreate ){
/* Open existing file, or create if it doesn't exist */ /* Open existing file, or create if it doesn't exist */
dwCreationDisposition = OPEN_ALWAYS; dwCreationDisposition = OPEN_ALWAYS;
}else{ }else{
/* Opens a file, only if it exists. */ /* Opens a file, only if it exists. */
dwCreationDisposition = OPEN_EXISTING; dwCreationDisposition = OPEN_EXISTING;
} }
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
if( flags & SQLITE_OPEN_DELETEONCLOSE ){
if( isDelete ){
#if SQLITE_OS_WINCE #if SQLITE_OS_WINCE
dwFlagsAndAttributes = FILE_ATTRIBUTE_HIDDEN; dwFlagsAndAttributes = FILE_ATTRIBUTE_HIDDEN;
isTemp = 1; isTemp = 1;
@@ -2089,6 +2137,7 @@ static int winOpen(
#if SQLITE_OS_WINCE #if SQLITE_OS_WINCE
dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS; dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
#endif #endif
if( isNT() ){ if( isNT() ){
h = CreateFileW((WCHAR*)zConverted, h = CreateFileW((WCHAR*)zConverted,
dwDesiredAccess, dwDesiredAccess,
@@ -2114,26 +2163,30 @@ static int winOpen(
); );
#endif #endif
} }
OSTRACE(("OPEN %d %s 0x%lx %s\n", OSTRACE(("OPEN %d %s 0x%lx %s\n",
h, zName, dwDesiredAccess, h, zName, dwDesiredAccess,
h==INVALID_HANDLE_VALUE ? "failed" : "ok")); h==INVALID_HANDLE_VALUE ? "failed" : "ok"));
if( h==INVALID_HANDLE_VALUE ){ if( h==INVALID_HANDLE_VALUE ){
pFile->lastErrno = GetLastError(); pFile->lastErrno = GetLastError();
free(zConverted); free(zConverted);
if( flags & SQLITE_OPEN_READWRITE ){ if( isReadWrite ){
return winOpen(pVfs, zName, id, return winOpen(pVfs, zName, id,
((flags|SQLITE_OPEN_READONLY)&~SQLITE_OPEN_READWRITE), pOutFlags); ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags);
}else{ }else{
return SQLITE_CANTOPEN_BKPT; return SQLITE_CANTOPEN_BKPT;
} }
} }
if( pOutFlags ){ if( pOutFlags ){
if( flags & SQLITE_OPEN_READWRITE ){ if( isReadWrite ){
*pOutFlags = SQLITE_OPEN_READWRITE; *pOutFlags = SQLITE_OPEN_READWRITE;
}else{ }else{
*pOutFlags = SQLITE_OPEN_READONLY; *pOutFlags = SQLITE_OPEN_READONLY;
} }
} }
memset(pFile, 0, sizeof(*pFile)); memset(pFile, 0, sizeof(*pFile));
pFile->pMethod = &winIoMethod; pFile->pMethod = &winIoMethod;
pFile->h = h; pFile->h = h;
@@ -2142,9 +2195,9 @@ static int winOpen(
pFile->pShm = 0; pFile->pShm = 0;
pFile->zPath = zName; pFile->zPath = zName;
pFile->sectorSize = getSectorSize(pVfs, zUtf8Name); pFile->sectorSize = getSectorSize(pVfs, zUtf8Name);
#if SQLITE_OS_WINCE #if SQLITE_OS_WINCE
if( (flags & (SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)) == if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
(SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)
&& !winceCreateLock(zName, pFile) && !winceCreateLock(zName, pFile)
){ ){
CloseHandle(h); CloseHandle(h);
@@ -2158,8 +2211,9 @@ static int winOpen(
{ {
free(zConverted); free(zConverted);
} }
OpenCounter(+1); OpenCounter(+1);
return SQLITE_OK; return rc;
} }
/* /*