2008-10-29 10:01:56 +03:00
|
|
|
# 2008 October 29
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
# This file implements regression tests for SQLite library.
|
|
|
|
#
|
2009-06-26 11:12:06 +04:00
|
|
|
# $Id: tkt3457.test,v 1.3 2009/06/26 07:12:07 danielk1977 Exp $
|
2008-10-29 10:01:56 +03:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
|
|
|
if {$tcl_platform(platform) != "unix"} {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
# To roll back a hot-journal file, the application needs read and write
|
|
|
|
# permission on the journal file in question. The following tests test
|
|
|
|
# the outcome of trying to rollback a hot-journal file when this is not
|
|
|
|
# the case.
|
|
|
|
#
|
|
|
|
# tkt3457-1.2: Application has neither read, nor write permission on
|
|
|
|
# the hot-journal file. Result: SQLITE_CANTOPEN.
|
|
|
|
#
|
|
|
|
# tkt3457-1.3: Application has write but not read permission on
|
|
|
|
# the hot-journal file. Result: SQLITE_CANTOPEN.
|
|
|
|
#
|
2013-01-05 02:26:47 +04:00
|
|
|
# tkt3457-1.4: Application has read but not write permission on
|
2008-10-29 10:01:56 +03:00
|
|
|
# the hot-journal file. Result: SQLITE_CANTOPEN.
|
|
|
|
#
|
|
|
|
# tkt3457-1.5: Application has read/write permission on the hot-journal
|
|
|
|
# file. Result: SQLITE_OK.
|
|
|
|
#
|
|
|
|
do_test tkt3457-1.1 {
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
INSERT INTO t1 VALUES(1, 2, 3);
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO t1 VALUES(4, 5, 6);
|
|
|
|
}
|
|
|
|
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy test.db bak.db
|
|
|
|
forcecopy test.db-journal bak.db-journal
|
2008-10-29 10:01:56 +03:00
|
|
|
|
2009-06-26 11:12:06 +04:00
|
|
|
# Fix the first journal-header in the journal-file. Because the
|
|
|
|
# journal file has not yet been synced, the 8-byte magic string at the
|
|
|
|
# start of the first journal-header has not been written by SQLite.
|
|
|
|
# So write it now.
|
|
|
|
set fd [open bak.db-journal a+]
|
|
|
|
fconfigure $fd -encoding binary -translation binary
|
|
|
|
seek $fd 0
|
|
|
|
puts -nonewline $fd "\xd9\xd5\x05\xf9\x20\xa1\x63\xd7"
|
|
|
|
close $fd
|
|
|
|
|
2008-10-29 10:01:56 +03:00
|
|
|
execsql COMMIT
|
|
|
|
} {}
|
|
|
|
|
2013-01-05 00:45:13 +04:00
|
|
|
# Disable fchmod to make sure SQLite itself does not try to change the
|
|
|
|
# permission bits on us
|
|
|
|
#
|
|
|
|
catch {
|
|
|
|
test_syscall install fchmod
|
|
|
|
test_syscall fault 1 1
|
|
|
|
}
|
|
|
|
|
2008-10-29 10:01:56 +03:00
|
|
|
do_test tkt3457-1.2 {
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy bak.db-journal test.db-journal
|
2008-10-29 10:01:56 +03:00
|
|
|
file attributes test.db-journal -permissions ---------
|
|
|
|
catchsql { SELECT * FROM t1 }
|
|
|
|
} {1 {unable to open database file}}
|
|
|
|
do_test tkt3457-1.3 {
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy bak.db-journal test.db-journal
|
2008-10-29 10:01:56 +03:00
|
|
|
file attributes test.db-journal -permissions -w--w--w-
|
|
|
|
catchsql { SELECT * FROM t1 }
|
|
|
|
} {1 {unable to open database file}}
|
|
|
|
do_test tkt3457-1.4 {
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy bak.db-journal test.db-journal
|
2008-10-29 10:01:56 +03:00
|
|
|
file attributes test.db-journal -permissions r--r--r--
|
|
|
|
catchsql { SELECT * FROM t1 }
|
|
|
|
} {1 {unable to open database file}}
|
|
|
|
|
|
|
|
do_test tkt3457-1.5 {
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy bak.db-journal test.db-journal
|
2008-10-29 10:01:56 +03:00
|
|
|
file attributes test.db-journal -permissions rw-rw-rw-
|
|
|
|
catchsql { SELECT * FROM t1 }
|
|
|
|
} {0 {1 2 3 4 5 6}}
|
|
|
|
|
2013-01-05 00:45:13 +04:00
|
|
|
# Reenable fchmod
|
|
|
|
catch {
|
|
|
|
test_syscall uninstall
|
|
|
|
test_syscall fault 0 0
|
|
|
|
}
|
|
|
|
|
2008-10-29 10:01:56 +03:00
|
|
|
finish_test
|