@@ -49,9 +49,7 @@ func (c cksmFile) ReadAt(p []byte, off int64) (n int, err error) {
4949 n , err = c .File .ReadAt (p , off )
5050 p = p [:n ]
5151
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 ) {
5553 c .init ((* [100 ]byte )(p ))
5654 }
5755
@@ -67,9 +65,7 @@ func (c cksmFile) ReadAt(p []byte, off int64) (n int, err error) {
6765}
6866
6967func (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 ) {
7369 c .init ((* [100 ]byte )(p ))
7470 }
7571
@@ -116,9 +112,11 @@ func (c cksmFile) fileControl(ctx context.Context, mod api.Module, op _FcntlOpco
116112 c .inCkpt = true
117113 case _FCNTL_CKPT_DONE :
118114 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+ }
122120 }
123121 return vfsFileControlImpl (ctx , mod , c .File , op , pArg )
124122}
@@ -135,6 +133,14 @@ func (f *cksmFlags) init(header *[100]byte) {
135133 }
136134}
137135
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+
138144func cksmCompute (a []byte ) (cksm [8 ]byte ) {
139145 var s1 , s2 uint32
140146 for len (a ) >= 8 {
0 commit comments