3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing that SQLite can follow symbolic links.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set testprefix symlink
19 # This only runs on unix.
20 if {$::tcl_platform(platform)!="unix"} {
25 # Ensure that test.db has been created.
28 CREATE TABLE t1(x, y);
31 # Test that SQLite follows symlinks when opening files.
35 file link test.db2 test.db
37 sqlite3_db_filename db2 main
38 } [file join [pwd] test.db]
40 # Test that if the symlink points to a file that does not exists, it is
41 # created when it is opened.
54 sqlite3_db_filename db2 main
55 } [file join [pwd] test.db]
58 # Test that a loop of symlinks cannot be opened.
62 # Note: Tcl [file link] command is too smart to create loops of symlinks.
63 exec ln -s test.db2 test.db
64 list [catch { sqlite3 db test.db } msg] $msg
65 } {1 {unable to open database file}}
67 # Test that overly large paths cannot be opened.
70 set name "test.db[string repeat x 502]"
71 list [catch { sqlite3 db $name } msg] $msg
72 } {1 {unable to open database file}}
74 set r [expr 510 - [string length test.db] - [string length [pwd]]]
75 set name "test.db[string repeat x $r]"
76 list [catch { sqlite3 db $name } msg] $msg
77 } {1 {unable to open database file}}
79 #-------------------------------------------------------------------------
80 # Test that journal and wal files are created next to the real file,
86 forcedelete test.db test.db2 test.db3
88 execsql { CREATE TABLE t1(x) }
89 file link test.db2 test.db
90 file link test.db3 test.db2
94 foreach {tn f} {1 test.db2 2 test.db3} {
97 file exists test.db-journal
102 INSERT INTO t1 VALUES(1);
104 file exists test.db-journal
107 list [file exists test2.db-journal] [file exists test3.db-journal]
112 PRAGMA journal_mode = wal;
113 INSERT INTO t1 VALUES(2);
115 file exists test.db-wal
118 list [file exists test2.db-wal] [file exists test3.db-wal]
120 do_execsql_test 2.$tn.6 {
124 do_execsql_test 2.$tn.7 {
126 PRAGMA journal_mode = delete;
130 # Try to open a ridiculously long pathname. Bug found by
131 # Kostya Serebryany using libFuzzer on 2015-11-30.
135 catch {sqlite3 db [string repeat [string repeat x 100]/ 6]} res
137 } {unable to open database file}
139 #-------------------------------------------------------------------------
140 # Test that relative symlinks that are not located in the cwd work.
148 file link y/test.db ../x/test.db
149 file link z/test.db ../y/test.db
151 PRAGMA journal_mode = wal;
152 CREATE TABLE t1(x, y);
153 INSERT INTO t1 VALUES('hello', 'world');
160 db eval { SELECT * FROM t1 }
163 list [file exists x/test.db-wal] [file exists y/test.db-wal]
169 db eval { SELECT * FROM t1 }
172 list [file exists x/test.db-wal] [file exists y/test.db-wal] \
173 [file exists z/test.db-wal]
179 file link w/test.db [file join [pwd] x/test.db]
185 db eval { SELECT * FROM t1 }
188 list [file exists x/test.db-wal] [file exists w/test.db-wal]