mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
VFS improvements.
This commit is contained in:
@@ -59,7 +59,7 @@ func (sliceVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag, e
|
||||
}
|
||||
|
||||
func (sliceVFS) Delete(name string, dirSync bool) error {
|
||||
// notest // OPEN_MEMORY
|
||||
// notest // no journals to delete
|
||||
return sqlite3.IOERR_DELETE
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ func Test_wal(t *testing.T) {
|
||||
|
||||
compareDBs(t, data, walDB)
|
||||
|
||||
err = serdes.Deserialize(db, "main", walDB)
|
||||
err = serdes.Deserialize(db, "temp", walDB)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -69,20 +69,26 @@ func (*SliceFile) Close() error { return nil }
|
||||
func (*SliceFile) Sync(flags vfs.SyncFlag) error { return nil }
|
||||
|
||||
// Lock implements [vfs.File].
|
||||
func (*SliceFile) Lock(lock vfs.LockLevel) error { return nil }
|
||||
func (*SliceFile) Lock(lock vfs.LockLevel) error {
|
||||
// notest // not concurrency safe
|
||||
return sqlite3.IOERR_LOCK
|
||||
}
|
||||
|
||||
// Unlock implements [vfs.File].
|
||||
func (*SliceFile) Unlock(lock vfs.LockLevel) error { return nil }
|
||||
func (*SliceFile) Unlock(lock vfs.LockLevel) error {
|
||||
// notest // not concurrency safe
|
||||
return sqlite3.IOERR_UNLOCK
|
||||
}
|
||||
|
||||
// CheckReservedLock implements [vfs.File].
|
||||
func (*SliceFile) CheckReservedLock() (bool, error) {
|
||||
// notest // OPEN_MEMORY
|
||||
// notest // not concurrency safe
|
||||
return false, sqlite3.IOERR_CHECKRESERVEDLOCK
|
||||
}
|
||||
|
||||
// SectorSize implements [vfs.File].
|
||||
func (*SliceFile) SectorSize() int {
|
||||
// notest // IOCAP_POWERSAFE_OVERWRITE
|
||||
// notest // safe default
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,14 @@ func UnwrapFile[T vfs.File](f vfs.File) (_ T, _ bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// WrapOpen helps wrap [vfs.VFS].
|
||||
func WrapOpen(f vfs.VFS, name string, flags vfs.OpenFlag) (file vfs.File, _ vfs.OpenFlag, err error) {
|
||||
if f, ok := f.(vfs.VFSFilename); name == "" && ok {
|
||||
return f.OpenFilename(nil, flags)
|
||||
}
|
||||
return f.Open(name, flags)
|
||||
}
|
||||
|
||||
// WrapOpenFilename helps wrap [vfs.VFSFilename].
|
||||
func WrapOpenFilename(f vfs.VFS, name *vfs.Filename, flags vfs.OpenFlag) (file vfs.File, _ vfs.OpenFlag, err error) {
|
||||
if f, ok := f.(vfs.VFSFilename); ok {
|
||||
|
||||
@@ -3,14 +3,19 @@ package readervfs
|
||||
import (
|
||||
"github.com/ncruces/go-sqlite3"
|
||||
"github.com/ncruces/go-sqlite3/util/ioutil"
|
||||
"github.com/ncruces/go-sqlite3/util/vfsutil"
|
||||
"github.com/ncruces/go-sqlite3/vfs"
|
||||
)
|
||||
|
||||
type readerVFS struct{}
|
||||
|
||||
func (readerVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag, error) {
|
||||
// Temp journals, as used by the sorter, use SliceFile.
|
||||
if flags&vfs.OPEN_TEMP_JOURNAL != 0 {
|
||||
return &vfsutil.SliceFile{}, flags | vfs.OPEN_MEMORY, nil
|
||||
}
|
||||
// Refuse to open all other file types.
|
||||
if flags&vfs.OPEN_MAIN_DB == 0 {
|
||||
// notest
|
||||
return nil, flags, sqlite3.CANTOPEN
|
||||
}
|
||||
readerMtx.RLock()
|
||||
@@ -22,12 +27,12 @@ func (readerVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag,
|
||||
}
|
||||
|
||||
func (readerVFS) Delete(name string, dirSync bool) error {
|
||||
// notest
|
||||
// notest // IOCAP_IMMUTABLE
|
||||
return sqlite3.IOERR_DELETE
|
||||
}
|
||||
|
||||
func (readerVFS) Access(name string, flag vfs.AccessFlag) (bool, error) {
|
||||
// notest
|
||||
// notest // IOCAP_IMMUTABLE
|
||||
return false, sqlite3.IOERR_ACCESS
|
||||
}
|
||||
|
||||
@@ -42,37 +47,37 @@ func (readerFile) Close() error {
|
||||
}
|
||||
|
||||
func (readerFile) WriteAt(b []byte, off int64) (n int, err error) {
|
||||
// notest
|
||||
// notest // IOCAP_IMMUTABLE
|
||||
return 0, sqlite3.IOERR_WRITE
|
||||
}
|
||||
|
||||
func (readerFile) Truncate(size int64) error {
|
||||
// notest
|
||||
// notest // IOCAP_IMMUTABLE
|
||||
return sqlite3.IOERR_TRUNCATE
|
||||
}
|
||||
|
||||
func (readerFile) Sync(flag vfs.SyncFlag) error {
|
||||
// notest
|
||||
// notest // IOCAP_IMMUTABLE
|
||||
return sqlite3.IOERR_FSYNC
|
||||
}
|
||||
|
||||
func (readerFile) Lock(lock vfs.LockLevel) error {
|
||||
// notest
|
||||
// notest // IOCAP_IMMUTABLE
|
||||
return sqlite3.IOERR_LOCK
|
||||
}
|
||||
|
||||
func (readerFile) Unlock(lock vfs.LockLevel) error {
|
||||
// notest
|
||||
// notest // IOCAP_IMMUTABLE
|
||||
return sqlite3.IOERR_UNLOCK
|
||||
}
|
||||
|
||||
func (readerFile) CheckReservedLock() (bool, error) {
|
||||
// notest
|
||||
// notest // IOCAP_IMMUTABLE
|
||||
return false, sqlite3.IOERR_CHECKRESERVEDLOCK
|
||||
}
|
||||
|
||||
func (readerFile) SectorSize() int {
|
||||
// notest
|
||||
// notest // IOCAP_IMMUTABLE
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user