-C Add\stests\sto\spagerfault.test.
-D 2010-07-14T08:20:36
+C On\sunix,\stry\sto\screate\sthe\s*-wal\sand\s*-shm\sfiles\swith\sthe\ssame\spermissions\sas\sthe\sassociated\sdatabase\sfile.
+D 2010-07-14T14:48:58
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F src/mutex_unix.c cf84466b4fdd2baa0d5a10bb19f08b2abc1ce42e
F src/mutex_w32.c 1fe0e735897be20e09dd6f53c3fb516c6b48c0eb
F src/notify.c cbfa66a836da3a51567209636e6a94059c137930
-F src/os.c a0ecbd198b92e60a3e3b8887a668df3f80b4f62f
+F src/os.c 60178f518c4d6c0dcb59f7292232281d7bea2dcf
F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9
F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
F src/os_os2.c 665876d5eec7585226b0a1cf5e18098de2b2da19
-F src/os_unix.c cfcb63d4aadadd75ef89c41563bf15332eef4e4e
+F src/os_unix.c 417a378a1941b9203d2613c082133fee85199f74
F src/os_win.c 61734aad7f50b28f3c76eb4b19b63472f6d825d9
F src/pager.c 78ca1e1f3315c8227431c403c04d791dccf242fb
F src/pager.h 879fdde5a102d2f21a3135d6f647530b21c2796c
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
F src/select.c 4903ff1bbd08b55cbce00ea43c645530de41b362
F src/shell.c fd4ccdb37c3b68de0623eb938a649e0990710714
-F src/sqlite.h.in 1bcca411e266054977ed2b149a242c5a71092904
+F src/sqlite.h.in c394e27c259dff2de8b5939ecddd30262eb901ad
F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
F src/sqliteInt.h 8e3bc49a0e9217ff489a6b8f70cfcba0f5ad7437
F src/sqliteLimit.h 196e2f83c3b444c4548fc1874f52f84fdbda40f3
F src/vdbemem.c 5e579abf6532001dfbee0e640dc34eae897a9807
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
-F src/wal.c 7dce9040d5ba6c575f337b298fce1a9c04eb2296
+F src/wal.c 60932f29302b978a5eb4c637dbbc2db1d70a536f
F src/wal.h 906c85760598b18584921fe08008435aa4eeeeb2
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
F src/where.c 926c83c6394e132a1c62b6b12ceeba7d55a34c19
F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
F test/vtab_shared.test 0eff9ce4f19facbe0a3e693f6c14b80711a4222d
F test/wal.test 1891e6f72dd437a1c2a48091aa9182ba17a8f780
-F test/wal2.test 85775a7f68013f8734da8f5131c108e29cdbe868
+F test/wal2.test b26d04c36361a3dd99b9c5a43658f12e0d197c70
F test/wal3.test d2ae7e66f973bd6b58ce49e546b2c00f44fe0485
F test/wal4.test 640be93f5422df37203aa5e7c06b24fb5e4a2439
F test/wal_common.tcl 895d76138043b86bdccf36494054bdabcf65837b
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P c73886ed7497c0daf798c3b02ca6f5a1c2addde3
-R 2b6e3a3412f1bfeb09d6b6b4e98d2ecb
+P b092f2a74bdc77c1f90ad3b4448cb68a891ecf63
+R c3e2391a3a0460d3db8727396fae83c1
U dan
-Z 5807910238b38b6913c9b3401b1c1e56
+Z 33764ba68244566e69f565fd4aced7cc
-b092f2a74bdc77c1f90ad3b4448cb68a891ecf63
\ No newline at end of file
+e5d180eed245437b61bfb257ee01e2571c93afe7
\ No newline at end of file
){
int rc;
DO_OS_MALLOC_TEST(0);
- /* 0x7f3f is a mask of SQLITE_OPEN_ flags that are valid to be passed
+ /* 0x87f3f is a mask of SQLITE_OPEN_ flags that are valid to be passed
** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
** reaching the VFS. */
- rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x7f3f, pFlagsOut);
+ rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x87f3f, pFlagsOut);
assert( rc==SQLITE_OK || pFile->pMethods==0 );
return rc;
}
pInode = pDbFd->pInode;
pShmNode = pInode->pShmNode;
if( pShmNode==0 ){
+ struct stat sStat; /* fstat() info for database file */
+
+ /* Call fstat() to figure out the permissions on the database file. If
+ ** a new *-shm file is created, an attempt will be made to create it
+ ** with the same permissions. The actual permissions the file is created
+ ** with are subject to the current umask setting.
+ */
+ if( fstat(pDbFd->h, &sStat) ){
+ rc = SQLITE_IOERR_FSTAT;
+ goto shm_open_err;
+ }
+
nShmFilename = 5 + (int)strlen(pDbFd->zPath);
pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
if( pShmNode==0 ){
goto shm_open_err;
}
- pShmNode->h = open(zShmFilename, O_RDWR|O_CREAT, 0664);
+ pShmNode->h = open(zShmFilename, O_RDWR|O_CREAT, (sStat.st_mode & 0777));
if( pShmNode->h<0 ){
rc = SQLITE_CANTOPEN_BKPT;
goto shm_open_err;
return pUnused;
}
+/*
+** This function is called by unixOpen() to determine the unix permissions
+** to create new files with. If no error occurs, then SQLite is returned
+** and a value suitable for passing as the third argument to open(2) is
+** written to *pMode. If an IO error occurs, an SQLite error code is
+** returned and the value of *pMode is not modified.
+**
+** If the file being opened is a temporary file, it is always created with
+** the octal permissions 0600 (read/writable by owner only). If the file
+** is a database, journal or master journal file, it is created with the
+** permissions mask SQLITE_DEFAULT_FILE_PERMISSIONS.
+**
+** Finally, if the file being opened is a WAL file, then this function
+** queries the file-system for the permissions on the corresponding database
+** file and sets *pMode to this value. Whenever possible, WAL files are
+** created using the same permissions as the associated database file.
+*/
+static int findCreateFileMode(
+ const char *zPath, /* Path of file (possibly) being created */
+ int flags, /* Flags passed as 4th argument to xOpen() */
+ mode_t *pMode /* OUT: Permissions to open file with */
+){
+ int rc = SQLITE_OK; /* Return Code */
+ if( flags & SQLITE_OPEN_WAL ){
+ char zDb[MAX_PATHNAME+1]; /* Database file path */
+ int nDb; /* Number of valid bytes in zDb */
+ struct stat sStat; /* Output of stat() on database file */
+
+ nDb = sqlite3Strlen30(zPath) - 4;
+ memcpy(zDb, zPath, nDb);
+ zDb[nDb] = '\0';
+ if( 0==stat(zDb, &sStat) ){
+ *pMode = sStat.st_mode & 0777;
+ }else{
+ rc = SQLITE_IOERR_FSTAT;
+ }
+ }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
+ *pMode = 0600;
+ }else{
+ *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS;
+ }
+ return rc;
+}
+
/*
** Open the file zPath.
**
** a file-descriptor on the directory too. The first time unixSync()
** is called the directory file descriptor will be fsync()ed and close()d.
*/
- int isOpenDirectory = (isCreate &&
- (eType==SQLITE_OPEN_MASTER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL)
- );
+ int isOpenDirectory = (isCreate && (
+ eType==SQLITE_OPEN_MASTER_JOURNAL
+ || eType==SQLITE_OPEN_MAIN_JOURNAL
+ || eType==SQLITE_OPEN_WAL
+ ));
/* 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.
assert(isExclusive==0 || isCreate);
assert(isDelete==0 || isCreate);
- /* The main DB, main journal, and master journal are never automatically
- ** deleted. Nor are they ever temporary files. */
+ /* 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_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
);
memset(p, 0, sizeof(unixFile));
openFlags |= (O_LARGEFILE|O_BINARY);
if( fd<0 ){
- mode_t openMode = (isDelete?0600:SQLITE_DEFAULT_FILE_PERMISSIONS);
+ mode_t openMode; /* Permissions to create file with */
+ rc = findCreateFileMode(zName, flags, &openMode);
+ if( rc!=SQLITE_OK ){
+ assert( !p->pUnused );
+ return rc;
+ }
fd = open(zName, openFlags, openMode);
OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
if( fd<0 && errno!=EISDIR && isReadWrite && !isExclusive ){
#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
+#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
/*
** CAPI3REF: Device Characteristics
pRet->zWalName = zWalName;
/* Open file handle on the write-ahead log file. */
- flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_JOURNAL);
+ flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL);
rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
if( rc!=SQLITE_OK ){
db2 close
tvfs delete
+#-------------------------------------------------------------------------
+# If a connection is required to create a WAL or SHM file, it creates
+# the new files with the same file-system permissions as the database
+# file itself. Test this.
+#
+if {$::tcl_platform(platform) == "unix"} {
+ faultsim_delete_and_reopen
+
+ set umask [exec /bin/sh -c umask]
+ do_test wal2-12.1 {
+ sqlite3 db test.db
+ execsql {
+ CREATE TABLE tx(y, z);
+ PRAGMA journal_mode = WAL;
+ }
+ db close
+ list [file exists test.db-wal] [file exists test.db-shm]
+ } {0 0}
+
+ foreach {tn permissions} {
+ 1 00644
+ 2 00666
+ 3 00600
+ 4 00755
+ } {
+ set effective [format %.5o [expr $permissions & ~$umask]]
+ do_test wal2-12.2.$tn.1 {
+ file attributes test.db -permissions $permissions
+ file attributes test.db -permissions
+ } $permissions
+ do_test wal2-12.2.$tn.2 {
+ list [file exists test.db-wal] [file exists test.db-shm]
+ } {0 0}
+ do_test wal2-12.2.$tn.3 {
+ sqlite3 db test.db
+ execsql { INSERT INTO tx DEFAULT VALUES }
+ list [file exists test.db-wal] [file exists test.db-shm]
+ } {1 1}
+ do_test wal2-12.2.$tn.4 {
+ list [file attr test.db-wal -perm] [file attr test.db-shm -perm]
+ } [list $effective $effective]
+ do_test wal2-12.2.$tn.5 {
+ db close
+ list [file exists test.db-wal] [file exists test.db-shm]
+ } {0 0}
+ }
+}
+
finish_test