/ Check-in [dc5308c7]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:If a hot-journal file is detected but the application does not have the required read/write permissions, return SQLITE_CANTOPEN. Prior to this change, SQLITE_BUSY was returned. Ticket #3457. (CVS 5849)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: dc5308c7629abe6a3bad21489c8e97087c264e5a
User & Date: danielk1977 2008-10-29 07:01:57
Context
2008-10-30
15:03
Add the sqlite3_extended_errcode() interface. Change to return SQLITE_BUSY instead of SQLITE_ERROR when a COMMIT is attempted and one or more queries are still pending. (CVS 5850) check-in: 4c6a90a1 user: drh tags: trunk
2008-10-29
07:01
If a hot-journal file is detected but the application does not have the required read/write permissions, return SQLITE_CANTOPEN. Prior to this change, SQLITE_BUSY was returned. Ticket #3457. (CVS 5849) check-in: dc5308c7 user: danielk1977 tags: trunk
2008-10-28
18:58
Remove the vestigial mem4 and mem6 memory allocators. Add the SQLITE_ZERO_MALLOC compile-time option and the mem0.c module to handle memory allocation for that case. (CVS 5848) check-in: 4651f590 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.499 2008/10/22 16:26:48 shane Exp $
           21  +** @(#) $Id: pager.c,v 1.500 2008/10/29 07:01:57 danielk1977 Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   
    26     26   /*
    27     27   ** Macros for troubleshooting.  Normally turned off
    28     28   */
................................................................................
  2636   2636           if( rc==SQLITE_OK ){
  2637   2637             if( res ){
  2638   2638               int fout = 0;
  2639   2639               int f = SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_JOURNAL;
  2640   2640               assert( !pPager->tempFile );
  2641   2641               rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, f, &fout);
  2642   2642               assert( rc!=SQLITE_OK || pPager->jfd->pMethods );
  2643         -            if( fout&SQLITE_OPEN_READONLY ){
  2644         -              rc = SQLITE_BUSY;
         2643  +            if( rc==SQLITE_OK && fout&SQLITE_OPEN_READONLY ){
         2644  +              rc = SQLITE_CANTOPEN;
  2645   2645                 sqlite3OsClose(pPager->jfd);
  2646   2646               }
  2647   2647             }else{
  2648   2648               /* If the journal does not exist, that means some other process
  2649   2649               ** has already rolled it back */
  2650   2650               rc = SQLITE_BUSY;
  2651   2651             }
  2652   2652           }
  2653   2653         }
  2654   2654         if( rc!=SQLITE_OK ){
  2655         -        if( rc!=SQLITE_NOMEM && rc!=SQLITE_IOERR_UNLOCK 
  2656         -         && rc!=SQLITE_IOERR_NOMEM 
  2657         -        ){
  2658         -          rc = SQLITE_BUSY;
  2659         -        }
  2660   2655           goto failed;
  2661   2656         }
  2662   2657         pPager->journalOpen = 1;
  2663   2658         pPager->journalStarted = 0;
  2664   2659         pPager->journalOff = 0;
  2665   2660         pPager->setMaster = 0;
  2666   2661         pPager->journalHdr = 0;

Added test/tkt3457.test.

            1  +# 2008 October 29
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.
           12  +#
           13  +# $Id: tkt3457.test,v 1.1 2008/10/29 07:01:57 danielk1977 Exp $
           14  +
           15  +set testdir [file dirname $argv0]
           16  +source $testdir/tester.tcl
           17  +
           18  +if {$tcl_platform(platform) != "unix"} {
           19  +  finish_test
           20  +  return
           21  +}
           22  +
           23  +#-----------------------------------------------------------------------
           24  +# To roll back a hot-journal file, the application needs read and write 
           25  +# permission on the journal file in question. The following tests test
           26  +# the outcome of trying to rollback a hot-journal file when this is not
           27  +# the case.
           28  +# 
           29  +#   tkt3457-1.2: Application has neither read, nor write permission on
           30  +#                the hot-journal file. Result: SQLITE_CANTOPEN.
           31  +#                
           32  +#   tkt3457-1.3: Application has write but not read permission on
           33  +#                the hot-journal file. Result: SQLITE_CANTOPEN.
           34  +#
           35  +#   tkt3457-1.4: Application has read but not write permission on
           36  +#                the hot-journal file. Result: SQLITE_CANTOPEN.
           37  +#
           38  +#   tkt3457-1.5: Application has read/write permission on the hot-journal 
           39  +#                file. Result: SQLITE_OK.
           40  +# 
           41  +do_test tkt3457-1.1 {
           42  +  execsql {
           43  +    CREATE TABLE t1(a, b, c);
           44  +    INSERT INTO t1 VALUES(1, 2, 3);
           45  +    BEGIN;
           46  +    INSERT INTO t1 VALUES(4, 5, 6);
           47  +  }
           48  +
           49  +  file copy -force test.db bak.db
           50  +  file copy -force test.db-journal bak.db-journal
           51  +
           52  +  execsql COMMIT
           53  +} {}
           54  +
           55  +do_test tkt3457-1.2 {
           56  +  file copy -force bak.db-journal test.db-journal
           57  +  file attributes test.db-journal -permissions ---------
           58  +  catchsql { SELECT * FROM t1 }
           59  +} {1 {unable to open database file}}
           60  +do_test tkt3457-1.3 {
           61  +  file copy -force bak.db-journal test.db-journal
           62  +  file attributes test.db-journal -permissions -w--w--w-
           63  +  catchsql { SELECT * FROM t1 }
           64  +} {1 {unable to open database file}}
           65  +do_test tkt3457-1.4 {
           66  +  file copy -force bak.db-journal test.db-journal
           67  +  file attributes test.db-journal -permissions r--r--r--
           68  +  catchsql { SELECT * FROM t1 }
           69  +} {1 {unable to open database file}}
           70  +
           71  +do_test tkt3457-1.5 {
           72  +  file copy -force bak.db-journal test.db-journal
           73  +  file attributes test.db-journal -permissions rw-rw-rw-
           74  +  catchsql { SELECT * FROM t1 }
           75  +} {0 {1 2 3 4 5 6}}
           76  +
           77  +finish_test
           78  +