@@ -45,15 +45,17 @@ func (h *hbshVFS) OpenFilename(name *vfs.Filename, flags vfs.OpenFlag) (file vfs
45
45
key , _ = hex .DecodeString (t [0 ])
46
46
} else if t , ok := params ["textkey" ]; ok {
47
47
key = h .hbsh .KDF (t [0 ])
48
+ } else if flags & vfs .OPEN_MAIN_DB != 0 {
49
+ // Main datatabases may have their key specified as a PRAGMA.
50
+ return & hbshFile {File : file , reset : h .hbsh }, flags , nil
48
51
}
49
52
hbsh = h .hbsh .HBSH (key )
50
53
}
51
54
52
- // Main datatabases may have their key specified later, as a PRAGMA.
53
- if hbsh != nil || flags & vfs .OPEN_MAIN_DB != 0 {
54
- return & hbshFile {File : file , hbsh : hbsh , reset : h .hbsh }, flags , nil
55
+ if hbsh == nil {
56
+ return nil , flags , sqlite3 .CANTOPEN
55
57
}
56
- return nil , flags , sqlite3 . CANTOPEN
58
+ return & hbshFile { File : file , hbsh : hbsh , reset : h . hbsh }, flags , nil
57
59
}
58
60
59
61
const (
@@ -96,8 +98,7 @@ func (h *hbshFile) ReadAt(p []byte, off int64) (n int, err error) {
96
98
// Only OPEN_MAIN_DB can have a missing key.
97
99
if off == 0 && len (p ) == 100 {
98
100
// SQLite is trying to read the header of a database file.
99
- // Pretend the file is empty so the key may specified later,
100
- // as a PRAGMA.
101
+ // Pretend the file is empty so the key may specified as a PRAGMA.
101
102
return 0 , io .EOF
102
103
}
103
104
return 0 , sqlite3 .CANTOPEN
0 commit comments