| 1 |
# 2019 November 18 |
| 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. The |
| 12 |
# focus of this file is testing that SQLite can follow symbolic links. |
| 13 |
# |
| 14 |
|
| 15 |
set testdir [file dirname $argv0] |
| 16 |
source $testdir/tester.tcl |
| 17 |
set testprefix symlink2 |
| 18 |
|
| 19 |
# This only runs on Windows. |
| 20 |
if {$::tcl_platform(platform) ne "windows"} { |
| 21 |
finish_test |
| 22 |
return |
| 23 |
} |
| 24 |
|
| 25 |
proc createWin32Symlink { link target } { |
| 26 |
exec -- $::env(ComSpec) /c mklink \ |
| 27 |
[file nativename $link] [file nativename $target] |
| 28 |
return "" |
| 29 |
} |
| 30 |
|
| 31 |
proc deleteWin32Symlink { link } { |
| 32 |
exec -- $::env(ComSpec) /c del [file nativename $link] |
| 33 |
return "" |
| 34 |
} |
| 35 |
|
| 36 |
proc canCreateWin32Symlink {} { |
| 37 |
set link [file join $::testdir lnk[pid].sym] |
| 38 |
if {[file exists $link]} { return 0 } |
| 39 |
set target [info nameofexecutable] |
| 40 |
if {[catch {createWin32Symlink $link $target}] == 0} { |
| 41 |
deleteWin32Symlink $link |
| 42 |
return 1 |
| 43 |
} |
| 44 |
return 0 |
| 45 |
} |
| 46 |
|
| 47 |
# Creating symlinks may require administrator privileges on Windows. |
| 48 |
if {![canCreateWin32Symlink]} { |
| 49 |
finish_test |
| 50 |
return |
| 51 |
} |
| 52 |
|
| 53 |
# Ensure that test.db has been created. |
| 54 |
# |
| 55 |
do_execsql_test 1.0 { |
| 56 |
CREATE TABLE t1(x, y); |
| 57 |
INSERT INTO t1 VALUES(1,9999); |
| 58 |
} |
| 59 |
|
| 60 |
forcedelete link.db |
| 61 |
do_test 2.0 { |
| 62 |
createWin32Symlink link.db test.db |
| 63 |
} {} |
| 64 |
|
| 65 |
do_test 2.1 { |
| 66 |
file exists test.db |
| 67 |
} {1} |
| 68 |
|
| 69 |
do_test 2.2 { |
| 70 |
file exists link.db |
| 71 |
} {1} |
| 72 |
|
| 73 |
do_test 3.1 { |
| 74 |
execsql { SELECT x, y FROM t1; } db |
| 75 |
} {1 9999} |
| 76 |
|
| 77 |
do_test 3.2 { |
| 78 |
sqlite3 db2 link.db |
| 79 |
execsql { SELECT x, y FROM t1; } db2 |
| 80 |
} {1 9999} |
| 81 |
|
| 82 |
do_test 3.3 { |
| 83 |
sqlite3 db3 test.db -nofollow true |
| 84 |
execsql { SELECT x, y FROM t1; } db3 |
| 85 |
} {1 9999} |
| 86 |
|
| 87 |
do_test 3.4 { |
| 88 |
db3 close |
| 89 |
} {} |
| 90 |
|
| 91 |
# The -nofollow option does not work on Windows |
| 92 |
do_test 3.5 { |
| 93 |
list [catch { |
| 94 |
sqlite3 db4 link.db -nofollow true |
| 95 |
execsql { SELECT x, y FROM t1; } db4 |
| 96 |
} res] $res |
| 97 |
} {0 {1 9999}} |
| 98 |
|
| 99 |
catch {db4 close} |
| 100 |
|
| 101 |
do_test 4.0 { |
| 102 |
db2 close |
| 103 |
deleteWin32Symlink link.db |
| 104 |
} {} |
| 105 |
|
| 106 |
do_test 4.1 { |
| 107 |
file exists test.db |
| 108 |
} {1} |
| 109 |
|
| 110 |
do_test 4.2 { |
| 111 |
file exists link.db |
| 112 |
} {0} |
| 113 |
|
| 114 |
do_test 5.1 { |
| 115 |
execsql { SELECT x, y FROM t1; } db |
| 116 |
} {1 9999} |
| 117 |
|
| 118 |
finish_test |