@@ -49,9 +49,7 @@ func (c cksmFile) ReadAt(p []byte, off int64) (n int, err error) {
49
49
n , err = c .File .ReadAt (p , off )
50
50
p = p [:n ]
51
51
52
- // SQLite is reading the header of a database file.
53
- if c .isDB && off == 0 && len (p ) >= 100 &&
54
- bytes .HasPrefix (p , []byte ("SQLite format 3\000 " )) {
52
+ if isHeader (c .isDB , p , off ) {
55
53
c .init ((* [100 ]byte )(p ))
56
54
}
57
55
@@ -67,9 +65,7 @@ func (c cksmFile) ReadAt(p []byte, off int64) (n int, err error) {
67
65
}
68
66
69
67
func (c cksmFile ) WriteAt (p []byte , off int64 ) (n int , err error ) {
70
- // SQLite is writing the first page of a database file.
71
- if (! c .isDB || off == 0 ) && sql3util .ValidPageSize (len (p )) &&
72
- bytes .HasPrefix (p , []byte ("SQLite format 3\000 " )) {
68
+ if isHeader (c .isDB , p , off ) {
73
69
c .init ((* [100 ]byte )(p ))
74
70
}
75
71
@@ -116,9 +112,11 @@ func (c cksmFile) fileControl(ctx context.Context, mod api.Module, op _FcntlOpco
116
112
c .inCkpt = true
117
113
case _FCNTL_CKPT_DONE :
118
114
c .inCkpt = false
119
- }
120
- if rc := vfsFileControlImpl (ctx , mod , c , op , pArg ); rc != _NOTFOUND {
121
- return rc
115
+ case _FCNTL_PRAGMA :
116
+ rc := vfsFileControlImpl (ctx , mod , c , op , pArg )
117
+ if rc != _NOTFOUND {
118
+ return rc
119
+ }
122
120
}
123
121
return vfsFileControlImpl (ctx , mod , c .File , op , pArg )
124
122
}
@@ -135,6 +133,14 @@ func (f *cksmFlags) init(header *[100]byte) {
135
133
}
136
134
}
137
135
136
+ func isHeader (isDB bool , p []byte , off int64 ) bool {
137
+ check := sql3util .ValidPageSize (len (p ))
138
+ if isDB {
139
+ check = off == 0 && len (p ) >= 100
140
+ }
141
+ return check && bytes .HasPrefix (p , []byte ("SQLite format 3\000 " ))
142
+ }
143
+
138
144
func cksmCompute (a []byte ) (cksm [8 ]byte ) {
139
145
var s1 , s2 uint32
140
146
for len (a ) >= 8 {
0 commit comments