Add the SQLITE_READONLY_ROLLBACK extended error code.

Do not try to set the permissions on journal or wal files except if the
filesize is initially zero (indicating that it is a new file.)

FossilOrigin-Name: ce4ac66a4b623a3cee1a63089dd5ba8341244f1e
This commit is contained in:
drh 2013-03-06 01:48:20 +00:00
commit a0272d8255
8 changed files with 53 additions and 15 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\sbug\sin\sthe\srecent\sincremental-vacuum\srelated\schanges.
D 2013-03-05T11:27:04.053
C Add\sthe\sSQLITE_READONLY_ROLLBACK\sextended\serror\scode.\nDo\snot\stry\sto\sset\sthe\spermissions\son\sjournal\sor\swal\sfiles\sexcept\sif\sthe\nfilesize\sis\sinitially\szero\s(indicating\sthat\sit\sis\sa\snew\sfile.)
D 2013-03-06T01:48:20.423
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 9a804abbd3cae82d196e4d33aba13239e32522a5
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -160,9 +160,9 @@ F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30
F src/os.c e1acdc09ff3ac2412945cca9766e2dcf4675f31c
F src/os.h 027491c77d2404c0a678bb3fb06286f331eb9b57
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
F src/os_unix.c 8964f621aaab1f2c9804fbbff4450d9811ef5548
F src/os_unix.c f6387eef0cf8f6b808738f4f3aa47e6132af0940
F src/os_win.c f7da4dc0a2545c0a430080380809946ae4d676d6
F src/pager.c bbe1eca2d1c81dcf163836ca317a6a6ea84441d8
F src/pager.c 582f8da52d0bd4b43d3bdaeba0ea7702c1f23702
F src/pager.h 1109a06578ec5574dc2c74cf8d9f69daf36fe3e0
F src/parse.y 5d5e12772845805fdfeb889163516b84fbb9ae95
F src/pcache.c f8043b433a57aba85384a531e3937a804432a346
@ -176,7 +176,7 @@ F src/resolve.c 9079da7d59aed2bb14ec8315bc7f720dd85b5b65
F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
F src/select.c e1c6f6abdf9f359f4e735cb8ae11d2f359bf52a9
F src/shell.c 7c41bfcd9e5bf9d96b9215f79b03a5b2b44a3bca
F src/sqlite.h.in 6296506a8fba279d8fa31f4abf01ab0cc92738a6
F src/sqlite.h.in 31045976254225e6bf046a96e87b40fa4c1d55e4
F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
F src/sqlite3ext.h 7183ab832e23db0f934494f16928da127a571d75
F src/sqliteInt.h 601c887f6d9c92e75551873c0a34711fff745bed
@ -184,7 +184,7 @@ F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c bedc37ec1a6bb9399944024d63f4c769971955a9
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
F src/tclsqlite.c 3213f3101e3b85f047d6e389da5a53d76d3d7540
F src/test1.c 50003e3beccad5569f757598fc7ce81b4f21aa7e
F src/test1.c ff3e68eedfbd858c9b89cf03e3db233cd29be1d0
F src/test2.c 4178056dd1e7d70f954ad8a1e3edb71a2a784daf
F src/test3.c 3c3c2407fa6ec7a19e24ae23f7cb439d0275a60d
F src/test4.c bf9fa9bece01de08e6f5e02314e4af5c13590dfa
@ -628,7 +628,7 @@ F test/misc3.test fe55130a43e444ee75e2156ff75dc96e964b5738
F test/misc4.test 9c078510fbfff05a9869a0b6d8b86a623ad2c4f6
F test/misc5.test 528468b26d03303b1f047146e5eefc941b9069f5
F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
F test/misc7.test f00dad9a004da659330013e6f21819d018b683d3
F test/misc7.test dd82ec9250b89178b96cd28b2aca70639d21e5b3
F test/misuse.test ba4fb5d1a6101d1c171ea38b3c613d0661c83054
F test/multiplex.test e08cc7177bd6d85990ee1d71100bb6c684c02256
F test/multiplex2.test 580ca5817c7edbe4cc68fa150609c9473393003a
@ -646,7 +646,7 @@ F test/orderby1.test f33968647da5c546528fe4d2bf86c6a6a2e5a7ae
F test/orderby2.test bc11009f7cd99d96b1b11e57b199b00633eb5b04
F test/orderby3.test 8619d06a3debdcd80a27c0fdea5c40b468854b99
F test/oserror.test 50417780d0e0d7cd23cf12a8277bb44024765df3
F test/pager1.test 8e14e7cfd2fbfe65eabead73af10ceeb2fc676aa
F test/pager1.test 31c04bec797dda1bde337810b52efa08d1f1f08e
F test/pager2.test 745b911dde3d1f24ae0870bd433dfa83d7c658c1
F test/pager3.test 3856d9c80839be0668efee1b74811b1b7f7fc95f
F test/pagerfault.test 452f2cc23e3bfcfa935f4442aec1da4fe1dc0442
@ -1036,7 +1036,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
P 8e0ced1af78d8c25a06423a8e7e337ac845155cc
R d0fc02cfce5e41e4c1a5be120b4b33d4
U dan
Z c4b64c03342d1e7d5813b1d9185813bd
P 717863fca6d58828bf9321bc8b169e385ad4263f 4f5f3aebe81c3cbe539db3e33ec38fa3de47e90b
R 4624808bc8666139dd43b7c21e0d98ea
U drh
Z 5a1f66c8d1d16d93a8aa4820fbcfcadc

View File

@ -1 +1 @@
717863fca6d58828bf9321bc8b169e385ad4263f
ce4ac66a4b623a3cee1a63089dd5ba8341244f1e

View File

@ -552,7 +552,10 @@ static int robust_open(const char *z, int f, mode_t m){
if( fd>=0 ){
if( m!=0 ){
struct stat statbuf;
if( osFstat(fd, &statbuf)==0 && (statbuf.st_mode&0777)!=m ){
if( osFstat(fd, &statbuf)==0
&& statbuf.st_size==0
&& (statbuf.st_mode&0777)!=m
){
osFchmod(fd, m);
}
}

View File

@ -4827,6 +4827,11 @@ int sqlite3PagerSharedLock(Pager *pPager){
goto failed;
}
if( bHotJournal ){
if( pPager->readOnly ){
rc = SQLITE_READONLY_ROLLBACK;
goto failed;
}
/* Get an EXCLUSIVE lock on the database file. At this point it is
** important that a RESERVED lock is not obtained on the way to the
** EXCLUSIVE lock. If it were, another process might open the

View File

@ -478,6 +478,7 @@ int sqlite3_exec(
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))

View File

@ -178,6 +178,7 @@ const char *sqlite3TestErrorName(int rc){
case SQLITE_CORRUPT_VTAB: zName = "SQLITE_CORRUPT_VTAB"; break;
case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break;
case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
default: zName = "SQLITE_Unknown"; break;
}
return zName;

View File

@ -488,6 +488,34 @@ do_test misc7-21.1 {
list $rc $msg
} {1 {unable to open database file}}
# Try to do hot-journal rollback with a read-only connection. The
# error code should be SQLITE_READONLY_ROLLBACK.
#
do_test misc7-22.1 {
db close
forcedelete test.db copy.db-journal
sqlite3 db test.db
execsql {
CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 2);
INSERT INTO t1 VALUES(3, 4);
}
db close
sqlite3 db test.db -readonly 1
catchsql {
INSERT INTO t1 VALUES(5, 6);
}
} {1 {attempt to write a readonly database}}
do_test misc7-22.2 { execsql { SELECT * FROM t1 } } {1 2 3 4}
do_test misc7-22.3 {
set fd [open test.db-journal w]
puts $fd [string repeat abc 1000]
close $fd
catchsql { SELECT * FROM t1 }
} {1 {attempt to write a readonly database}}
do_test misc7-22.4 {
sqlite3_extended_errcode db
} SQLITE_READONLY_ROLLBACK
db close
forcedelete test.db

View File

@ -752,7 +752,7 @@ sqlite3 db test.db -readonly 1
do_catchsql_test pager1.4.5.6 {
SELECT * FROM t1;
SELECT * FROM t2;
} {1 {disk I/O error}}
} {1 {attempt to write a readonly database}}
db close
# Snapshot the file-system just before multi-file commit. Save the name