mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-11 21:49:13 +00:00
VFS utilities.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
// Package fsutil implements filesystem utility functions.
|
// Package fsutil implements filesystem utilities.
|
||||||
package fsutil
|
package fsutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
// Package ioutil implements I/O utility functions.
|
// Package ioutil implements I/O utilities.
|
||||||
package ioutil
|
package ioutil
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
// Package osutil implements operating system utility functions.
|
// Package osutil implements operating system utilities.
|
||||||
package osutil
|
package osutil
|
||||||
|
|||||||
132
util/vfsutil/wrap.go
Normal file
132
util/vfsutil/wrap.go
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
// Package vtabutil implements virtual filesystem utilities.
|
||||||
|
package vfsutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ncruces/go-sqlite3"
|
||||||
|
"github.com/ncruces/go-sqlite3/vfs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WrapSharedMemory helps wrap [vfs.FileSharedMemory].
|
||||||
|
func WrapSharedMemory(f vfs.File) vfs.SharedMemory {
|
||||||
|
if f, ok := f.(vfs.FileSharedMemory); ok {
|
||||||
|
return f.SharedMemory()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapChunkSize helps wrap [vfs.FileChunkSize].
|
||||||
|
func WrapChunkSize(f vfs.File, size int) {
|
||||||
|
if f, ok := f.(vfs.FileChunkSize); ok {
|
||||||
|
f.ChunkSize(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapSizeHint helps wrap [vfs.FileSizeHint].
|
||||||
|
func WrapSizeHint(f vfs.File, size int64) error {
|
||||||
|
if f, ok := f.(vfs.FileSizeHint); ok {
|
||||||
|
return f.SizeHint(size)
|
||||||
|
}
|
||||||
|
return sqlite3.NOTFOUND
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapHasMoved helps wrap [vfs.FileHasMoved].
|
||||||
|
func WrapHasMoved(f vfs.File) (bool, error) {
|
||||||
|
if f, ok := f.(vfs.FileHasMoved); ok {
|
||||||
|
return f.HasMoved()
|
||||||
|
}
|
||||||
|
return false, sqlite3.NOTFOUND
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapOverwrite helps wrap [vfs.FileOverwrite].
|
||||||
|
func WrapOverwrite(f vfs.File) error {
|
||||||
|
if f, ok := f.(vfs.FileOverwrite); ok {
|
||||||
|
return f.Overwrite()
|
||||||
|
}
|
||||||
|
return sqlite3.NOTFOUND
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapPersistentWAL helps wrap [vfs.FilePersistentWAL].
|
||||||
|
func WrapPersistentWAL(f vfs.File) bool {
|
||||||
|
if f, ok := f.(vfs.FilePersistentWAL); ok {
|
||||||
|
return f.PersistentWAL()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapSetPersistentWAL helps wrap [vfs.FilePersistentWAL].
|
||||||
|
func WrapSetPersistentWAL(f vfs.File, keepWAL bool) {
|
||||||
|
if f, ok := f.(vfs.FilePersistentWAL); ok {
|
||||||
|
f.SetPersistentWAL(keepWAL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapPowersafeOverwrite helps wrap [vfs.FilePowersafeOverwrite].
|
||||||
|
func WrapPowersafeOverwrite(f vfs.File) bool {
|
||||||
|
if f, ok := f.(vfs.FilePowersafeOverwrite); ok {
|
||||||
|
return f.PowersafeOverwrite()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapSetPowersafeOverwrite helps wrap [vfs.FilePowersafeOverwrite].
|
||||||
|
func WrapSetPowersafeOverwrite(f vfs.File, psow bool) {
|
||||||
|
if f, ok := f.(vfs.FilePowersafeOverwrite); ok {
|
||||||
|
f.SetPowersafeOverwrite(psow)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapCommitPhaseTwo helps wrap [vfs.FileCommitPhaseTwo].
|
||||||
|
func WrapCommitPhaseTwo(f vfs.File) error {
|
||||||
|
if f, ok := f.(vfs.FileCommitPhaseTwo); ok {
|
||||||
|
return f.CommitPhaseTwo()
|
||||||
|
}
|
||||||
|
return sqlite3.NOTFOUND
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapBeginAtomicWrite helps wrap [vfs.FileBatchAtomicWrite].
|
||||||
|
func WrapBeginAtomicWrite(f vfs.File) error {
|
||||||
|
if f, ok := f.(vfs.FileBatchAtomicWrite); ok {
|
||||||
|
return f.BeginAtomicWrite()
|
||||||
|
}
|
||||||
|
return sqlite3.NOTFOUND
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapCommitAtomicWrite helps wrap [vfs.FileBatchAtomicWrite].
|
||||||
|
func WrapCommitAtomicWrite(f vfs.File) error {
|
||||||
|
if f, ok := f.(vfs.FileBatchAtomicWrite); ok {
|
||||||
|
return f.CommitAtomicWrite()
|
||||||
|
}
|
||||||
|
return sqlite3.NOTFOUND
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapRollbackAtomicWrite helps wrap [vfs.FileBatchAtomicWrite].
|
||||||
|
func WrapRollbackAtomicWrite(f vfs.File) error {
|
||||||
|
if f, ok := f.(vfs.FileBatchAtomicWrite); ok {
|
||||||
|
return f.RollbackAtomicWrite()
|
||||||
|
}
|
||||||
|
return sqlite3.NOTFOUND
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapCheckpointDone helps wrap [vfs.FileCheckpoint].
|
||||||
|
func WrapCheckpointDone(f vfs.File) error {
|
||||||
|
if f, ok := f.(vfs.FileCheckpoint); ok {
|
||||||
|
return f.CheckpointDone()
|
||||||
|
}
|
||||||
|
return sqlite3.NOTFOUND
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapCheckpointStart helps wrap [vfs.FileCheckpoint].
|
||||||
|
func WrapCheckpointStart(f vfs.File) error {
|
||||||
|
if f, ok := f.(vfs.FileCheckpoint); ok {
|
||||||
|
return f.CheckpointStart()
|
||||||
|
}
|
||||||
|
return sqlite3.NOTFOUND
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapPragma helps wrap [vfs.FilePragma].
|
||||||
|
func WrapPragma(f vfs.File, name, value string) (string, error) {
|
||||||
|
if f, ok := f.(vfs.FilePragma); ok {
|
||||||
|
return f.Pragma(name, value)
|
||||||
|
}
|
||||||
|
return "", sqlite3.NOTFOUND
|
||||||
|
}
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
// Package vtabutil implements virtual table utility functions.
|
// Package vtabutil implements virtual table utilities.
|
||||||
package vtabutil
|
package vtabutil
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ncruces/go-sqlite3"
|
"github.com/ncruces/go-sqlite3"
|
||||||
"github.com/ncruces/go-sqlite3/internal/util"
|
"github.com/ncruces/go-sqlite3/internal/util"
|
||||||
|
"github.com/ncruces/go-sqlite3/util/vfsutil"
|
||||||
"github.com/ncruces/go-sqlite3/vfs"
|
"github.com/ncruces/go-sqlite3/vfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -90,10 +91,7 @@ func (h *hbshFile) Pragma(name string, value string) (string, error) {
|
|||||||
key = h.init.KDF(value)
|
key = h.init.KDF(value)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if f, ok := h.File.(vfs.FilePragma); ok {
|
return vfsutil.WrapPragma(h.File, name, value)
|
||||||
return f.Pragma(name, value)
|
|
||||||
}
|
|
||||||
return "", sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.hbsh = h.init.HBSH(key); h.hbsh != nil {
|
if h.hbsh = h.init.HBSH(key); h.hbsh != nil {
|
||||||
@@ -209,92 +207,55 @@ func (h *hbshFile) DeviceCharacteristics() vfs.DeviceCharacteristic {
|
|||||||
// Wrap optional methods.
|
// Wrap optional methods.
|
||||||
|
|
||||||
func (h *hbshFile) SharedMemory() vfs.SharedMemory {
|
func (h *hbshFile) SharedMemory() vfs.SharedMemory {
|
||||||
if f, ok := h.File.(vfs.FileSharedMemory); ok {
|
return vfsutil.WrapSharedMemory(h.File)
|
||||||
return f.SharedMemory()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hbshFile) ChunkSize(size int) {
|
func (h *hbshFile) ChunkSize(size int) {
|
||||||
if f, ok := h.File.(vfs.FileChunkSize); ok {
|
size = (size + (blockSize - 1)) &^ (blockSize - 1) // round up
|
||||||
size = (size + (blockSize - 1)) &^ (blockSize - 1) // round up
|
vfsutil.WrapChunkSize(h.File, size)
|
||||||
f.ChunkSize(size)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hbshFile) SizeHint(size int64) error {
|
func (h *hbshFile) SizeHint(size int64) error {
|
||||||
if f, ok := h.File.(vfs.FileSizeHint); ok {
|
size = (size + (blockSize - 1)) &^ (blockSize - 1) // round up
|
||||||
size = (size + (blockSize - 1)) &^ (blockSize - 1) // round up
|
return vfsutil.WrapSizeHint(h.File, size)
|
||||||
return f.SizeHint(size)
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hbshFile) HasMoved() (bool, error) {
|
func (h *hbshFile) HasMoved() (bool, error) {
|
||||||
if f, ok := h.File.(vfs.FileHasMoved); ok {
|
return vfsutil.WrapHasMoved(h.File) // notest
|
||||||
return f.HasMoved()
|
|
||||||
}
|
|
||||||
return false, sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hbshFile) Overwrite() error {
|
func (h *hbshFile) Overwrite() error {
|
||||||
if f, ok := h.File.(vfs.FileOverwrite); ok {
|
return vfsutil.WrapOverwrite(h.File) // notest
|
||||||
return f.Overwrite()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hbshFile) PersistentWAL() bool {
|
func (h *hbshFile) PersistentWAL() bool {
|
||||||
if f, ok := h.File.(vfs.FilePersistentWAL); ok {
|
return vfsutil.WrapPersistentWAL(h.File) // notest
|
||||||
return f.PersistentWAL()
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hbshFile) SetPersistentWAL(keepWAL bool) {
|
func (h *hbshFile) SetPersistentWAL(keepWAL bool) {
|
||||||
if f, ok := h.File.(vfs.FilePersistentWAL); ok {
|
vfsutil.WrapSetPersistentWAL(h.File, keepWAL) // notest
|
||||||
f.SetPersistentWAL(keepWAL)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hbshFile) CommitPhaseTwo() error {
|
func (h *hbshFile) CommitPhaseTwo() error {
|
||||||
if f, ok := h.File.(vfs.FileCommitPhaseTwo); ok {
|
return vfsutil.WrapCommitPhaseTwo(h.File) // notest
|
||||||
return f.CommitPhaseTwo()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hbshFile) BeginAtomicWrite() error {
|
func (h *hbshFile) BeginAtomicWrite() error {
|
||||||
if f, ok := h.File.(vfs.FileBatchAtomicWrite); ok {
|
return vfsutil.WrapBeginAtomicWrite(h.File) // notest
|
||||||
return f.BeginAtomicWrite()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hbshFile) CommitAtomicWrite() error {
|
func (h *hbshFile) CommitAtomicWrite() error {
|
||||||
if f, ok := h.File.(vfs.FileBatchAtomicWrite); ok {
|
return vfsutil.WrapCommitAtomicWrite(h.File) // notest
|
||||||
return f.CommitAtomicWrite()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hbshFile) RollbackAtomicWrite() error {
|
func (h *hbshFile) RollbackAtomicWrite() error {
|
||||||
if f, ok := h.File.(vfs.FileBatchAtomicWrite); ok {
|
return vfsutil.WrapRollbackAtomicWrite(h.File) // notest
|
||||||
return f.RollbackAtomicWrite()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hbshFile) CheckpointDone() error {
|
func (h *hbshFile) CheckpointDone() error {
|
||||||
if f, ok := h.File.(vfs.FileCheckpoint); ok {
|
return vfsutil.WrapCheckpointDone(h.File) // notest
|
||||||
return f.CheckpointDone()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hbshFile) CheckpointStart() error {
|
func (h *hbshFile) CheckpointStart() error {
|
||||||
if f, ok := h.File.(vfs.FileCheckpoint); ok {
|
return vfsutil.WrapCheckpointStart(h.File) // notest
|
||||||
return f.CheckpointStart()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ncruces/go-sqlite3"
|
"github.com/ncruces/go-sqlite3"
|
||||||
"github.com/ncruces/go-sqlite3/internal/util"
|
"github.com/ncruces/go-sqlite3/internal/util"
|
||||||
|
"github.com/ncruces/go-sqlite3/util/vfsutil"
|
||||||
"github.com/ncruces/go-sqlite3/vfs"
|
"github.com/ncruces/go-sqlite3/vfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -85,10 +86,7 @@ func (x *xtsFile) Pragma(name string, value string) (string, error) {
|
|||||||
key = x.init.KDF(value)
|
key = x.init.KDF(value)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if f, ok := x.File.(vfs.FilePragma); ok {
|
return vfsutil.WrapPragma(x.File, name, value)
|
||||||
return f.Pragma(name, value)
|
|
||||||
}
|
|
||||||
return "", sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if x.cipher = x.init.XTS(key); x.cipher != nil {
|
if x.cipher = x.init.XTS(key); x.cipher != nil {
|
||||||
@@ -205,92 +203,55 @@ func (x *xtsFile) DeviceCharacteristics() vfs.DeviceCharacteristic {
|
|||||||
// Wrap optional methods.
|
// Wrap optional methods.
|
||||||
|
|
||||||
func (x *xtsFile) SharedMemory() vfs.SharedMemory {
|
func (x *xtsFile) SharedMemory() vfs.SharedMemory {
|
||||||
if f, ok := x.File.(vfs.FileSharedMemory); ok {
|
return vfsutil.WrapSharedMemory(x.File)
|
||||||
return f.SharedMemory()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *xtsFile) ChunkSize(size int) {
|
func (x *xtsFile) ChunkSize(size int) {
|
||||||
if f, ok := x.File.(vfs.FileChunkSize); ok {
|
size = (size + (sectorSize - 1)) &^ (sectorSize - 1) // round up
|
||||||
size = (size + (sectorSize - 1)) &^ (sectorSize - 1) // round up
|
vfsutil.WrapChunkSize(x.File, size)
|
||||||
f.ChunkSize(size)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *xtsFile) SizeHint(size int64) error {
|
func (x *xtsFile) SizeHint(size int64) error {
|
||||||
if f, ok := x.File.(vfs.FileSizeHint); ok {
|
size = (size + (sectorSize - 1)) &^ (sectorSize - 1) // round up
|
||||||
size = (size + (sectorSize - 1)) &^ (sectorSize - 1) // round up
|
return vfsutil.WrapSizeHint(x.File, size)
|
||||||
return f.SizeHint(size)
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *xtsFile) HasMoved() (bool, error) {
|
func (x *xtsFile) HasMoved() (bool, error) {
|
||||||
if f, ok := x.File.(vfs.FileHasMoved); ok {
|
return vfsutil.WrapHasMoved(x.File) // notest
|
||||||
return f.HasMoved()
|
|
||||||
}
|
|
||||||
return false, sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *xtsFile) Overwrite() error {
|
func (x *xtsFile) Overwrite() error {
|
||||||
if f, ok := x.File.(vfs.FileOverwrite); ok {
|
return vfsutil.WrapOverwrite(x.File) // notest
|
||||||
return f.Overwrite()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *xtsFile) PersistentWAL() bool {
|
func (x *xtsFile) PersistentWAL() bool {
|
||||||
if f, ok := x.File.(vfs.FilePersistentWAL); ok {
|
return vfsutil.WrapPersistentWAL(x.File) // notest
|
||||||
return f.PersistentWAL()
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *xtsFile) SetPersistentWAL(keepWAL bool) {
|
func (x *xtsFile) SetPersistentWAL(keepWAL bool) {
|
||||||
if f, ok := x.File.(vfs.FilePersistentWAL); ok {
|
vfsutil.WrapSetPersistentWAL(x.File, keepWAL) // notest
|
||||||
f.SetPersistentWAL(keepWAL)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *xtsFile) CommitPhaseTwo() error {
|
func (x *xtsFile) CommitPhaseTwo() error {
|
||||||
if f, ok := x.File.(vfs.FileCommitPhaseTwo); ok {
|
return vfsutil.WrapCommitPhaseTwo(x.File) // notest
|
||||||
return f.CommitPhaseTwo()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *xtsFile) BeginAtomicWrite() error {
|
func (x *xtsFile) BeginAtomicWrite() error {
|
||||||
if f, ok := x.File.(vfs.FileBatchAtomicWrite); ok {
|
return vfsutil.WrapBeginAtomicWrite(x.File) // notest
|
||||||
return f.BeginAtomicWrite()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *xtsFile) CommitAtomicWrite() error {
|
func (x *xtsFile) CommitAtomicWrite() error {
|
||||||
if f, ok := x.File.(vfs.FileBatchAtomicWrite); ok {
|
return vfsutil.WrapCommitAtomicWrite(x.File) // notest
|
||||||
return f.CommitAtomicWrite()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *xtsFile) RollbackAtomicWrite() error {
|
func (x *xtsFile) RollbackAtomicWrite() error {
|
||||||
if f, ok := x.File.(vfs.FileBatchAtomicWrite); ok {
|
return vfsutil.WrapRollbackAtomicWrite(x.File) // notest
|
||||||
return f.RollbackAtomicWrite()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *xtsFile) CheckpointDone() error {
|
func (x *xtsFile) CheckpointDone() error {
|
||||||
if f, ok := x.File.(vfs.FileCheckpoint); ok {
|
return vfsutil.WrapCheckpointDone(x.File) // notest
|
||||||
return f.CheckpointDone()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *xtsFile) CheckpointStart() error {
|
func (x *xtsFile) CheckpointStart() error {
|
||||||
if f, ok := x.File.(vfs.FileCheckpoint); ok {
|
return vfsutil.WrapCheckpointStart(x.File) // notest
|
||||||
return f.CheckpointStart()
|
|
||||||
}
|
|
||||||
return sqlite3.NOTFOUND
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user